
using System.Web.UI.HtmlControls;
using System;
using System.Configuration;
using System.Drawing;
using System.Data;
using System.Web.UI.WebControls;
using Microsoft.VisualBasic;
using System.Collections;
using System.Web.UI;
using System.Web;


using System.IO;
using System.Text;
using System.Drawing.Imaging;
//using com.ddsc.database;
using DDSC.OracleADO;
using com.ddsc.common;
using SMAS;
using System.Resources;
using System.Data.OracleClient;

//P3513S1029-解決建議售價(含稅)四捨五不入問題 Modify by JoeChou

namespace smasb2b
{
    public class VNDW0031 : BasePage
    {
        //版本  修改日期  修改人員  修改案號    修　改　內　容
        //－－  －－－－  －－－－  －－－－－  －－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－
        //0002  20090224  JoeChou   P3109M0050  前後台新舊報價流程修改
        //----------------------------------------------------------------------------------------------------------


        #region  Web Form 設計工具產生的程式碼

        //此為 Web Form 設計工具所需的呼叫。
        [System.Diagnostics.DebuggerStepThrough()]
        private void InitializeComponent()
        {

        }
        protected ddscControlLibrary.SubmitButtonCtrl SubmitButtonCtrl2;
        protected System.Web.UI.HtmlControls.HtmlInputHidden hidPAYMENT_TERM_NO;
        protected System.Web.UI.HtmlControls.HtmlInputHidden hidCURRENCY_TYPE;
        protected System.Web.UI.HtmlControls.HtmlInputHidden hidDELIVERY_TERM;
        protected System.Web.UI.HtmlControls.HtmlInputHidden hidSUPPLY_PRICE;
        protected System.Web.UI.WebControls.Label lblCODE_SEQ;
        protected ddscControlLibrary.InputBoxCtrl txtCODE_SEQ;
        protected System.Web.UI.WebControls.Label lblLEAD_TIME_ERR;
        protected System.Web.UI.WebControls.Label lblEXP_DATELINE_ERR;
        protected System.Web.UI.WebControls.Label lblSUPPLY_PRICE_ERR;
        protected System.Web.UI.WebControls.Label lblDIMENSION_L_ERR;
        protected System.Web.UI.WebControls.Label lblDIMENSION_W_ERR;
        protected System.Web.UI.WebControls.Label lblDIMENSION_H_ERR;
        protected System.Web.UI.WebControls.Label lblGROSS_WEIGHT_ERR;
        protected System.Web.UI.HtmlControls.HtmlInputButton btnVIEW1;
        protected System.Web.UI.HtmlControls.HtmlInputButton btnVIEW2;
        protected System.Web.UI.HtmlControls.HtmlInputButton btnVIEW3;
        protected System.Web.UI.HtmlControls.HtmlInputHidden hidSERIAL_NO1;
        protected System.Web.UI.HtmlControls.HtmlInputHidden hidSERIAL_NO2;
        protected System.Web.UI.HtmlControls.HtmlInputHidden hidSERIAL_NO3;
        protected System.Web.UI.WebControls.Label lblCOEFFICIENT_ERR;
        protected System.Web.UI.WebControls.Label Label29;
        protected ddscControlLibrary.InputBoxCtrl txtENGLISH_FULLNAME;
        protected System.Web.UI.WebControls.Label lblENGLISH_FULLNAME;
        protected System.Web.UI.WebControls.Label lblCHINESE_FULLNAME;
        protected ddscControlLibrary.InputBoxCtrl txtCHINESE_FULLNAME;
        protected System.Web.UI.WebControls.RadioButtonList rdoMATERIAL_TYPE;
        protected System.Web.UI.WebControls.RadioButtonList rdoCONSIGNED;
        protected ddscControlLibrary.InputBoxCtrl txtLEAD_TIME;
        protected ddscControlLibrary.InputBoxCtrl txtEXP_DATELINE;
        protected System.Web.UI.WebControls.DropDownList drpPACKAGE_UNIT;
        protected ddscControlLibrary.InputBoxCtrl txtSUPPLY_PRICE;
        protected System.Web.UI.WebControls.Label lblMATERIAL_TYPE;
        protected System.Web.UI.WebControls.Label lblCONSIGNED;
        protected System.Web.UI.WebControls.Label lblLEAD_TIME;
        protected System.Web.UI.WebControls.Label lblEXP_DATELINE;
        protected System.Web.UI.WebControls.Label lblSUPPLY_PRICE;
        protected System.Web.UI.WebControls.Label lblCOEFFICIENT;
        protected ddscControlLibrary.InputBoxCtrl txtCOEFFICIENT;
        protected ddscControlLibrary.InputBoxCtrl txtPACK_DETAIL;
        protected ddscControlLibrary.InputBoxCtrl txtDIMENSION_L;
        protected System.Web.UI.WebControls.Label lblGROSS_WEIGHT;
        protected ddscControlLibrary.InputBoxCtrl txtGROSS_WEIGHT;

        protected System.Web.UI.WebControls.CheckBox chkDEL1;
        protected System.Web.UI.WebControls.CheckBox chkDEL2;
        protected System.Web.UI.WebControls.CheckBox chkDEL3;
        protected ddscControlLibrary.InputBoxCtrl txtPIC_NO1;
        protected ddscControlLibrary.InputBoxCtrl txtPIC_NO2;
        protected ddscControlLibrary.InputBoxCtrl txtPIC_NO3;
        protected System.Web.UI.HtmlControls.HtmlInputFile txtPATH1;
        protected System.Web.UI.HtmlControls.HtmlInputFile txtPATH2;
        protected System.Web.UI.HtmlControls.HtmlInputFile txtPATH3;
        protected System.Web.UI.WebControls.Label lblDEL;
        protected System.Web.UI.WebControls.Label lblPIC_NO;
        protected System.Web.UI.WebControls.Label lblPATH1;
        protected System.Web.UI.WebControls.Label lblDESCRIPTION1;
        protected System.Web.UI.WebControls.Label lblVIEW;
        protected System.Web.UI.WebControls.Label lblPACK_DETAIL;
        protected System.Web.UI.WebControls.Label lblDIMENSION;
        protected System.Web.UI.WebControls.Label lblDIMENSION_L;
        protected System.Web.UI.WebControls.Label lblDIMENSION_W;
        protected System.Web.UI.WebControls.Label lblDIMENSION_H;
        protected System.Web.UI.WebControls.Label lblMATERIAL_UPLOAD;
        protected System.Web.UI.WebControls.Label lblMATER_SET;
        protected System.Web.UI.WebControls.Label lblBASIC;
        protected System.Web.UI.HtmlControls.HtmlImage IMG1;
        protected ddscControlLibrary.SubmitButtonCtrl btnSave;
        protected ddscControlLibrary.SubmitButtonCtrl btnDel;
        protected ddscControlLibrary.SubmitButtonCtrl btnExit;
        protected ddscControlLibrary.InputBoxCtrl txtDIMENSION_W;
        protected ddscControlLibrary.InputBoxCtrl txtDIMENSION_H;
        protected System.Web.UI.WebControls.Label lblPATH1_ERR;
        protected System.Web.UI.WebControls.Label lblPATH2_ERR;
        protected System.Web.UI.WebControls.Label lblPATH3_ERR;
        protected System.Web.UI.HtmlControls.HtmlInputHidden hidCLASS;
        protected System.Web.UI.WebControls.Label lblMSG011;
        protected System.Web.UI.WebControls.Label lblKG;
        protected System.Web.UI.HtmlControls.HtmlInputHidden hidlangauage;
        protected System.Web.UI.WebControls.Label lblPURCHASE_NO;
        protected ddscControlLibrary.InputBoxCtrl txtPURCHASE_NO;
        protected System.Web.UI.WebControls.Label lblADVISED_PRICE;
        protected System.Web.UI.WebControls.Label lblDUTY_FREE_PRICE;
        protected ddscControlLibrary.InputBoxCtrl txtADVISED_PRICE;
        protected ddscControlLibrary.InputBoxCtrl txtAVERAGE_PRICE;
        protected ddscControlLibrary.InputBoxCtrl txtDUTY_FREE_PRICE;
        protected System.Web.UI.WebControls.Label lblPAYMENT_TERM_NO;
        protected System.Web.UI.WebControls.DropDownList drpPAYMENT_TERM_NO;
        protected System.Web.UI.WebControls.Label lblDELIVERY_TERM;
        protected System.Web.UI.WebControls.DropDownList drpDELIVERY_TERM;
        protected System.Web.UI.WebControls.Label lblSEAPORT;
        protected ddscControlLibrary.InputBoxCtrl txtSEAPORT;
        protected System.Web.UI.WebControls.Label lblDELIVERY_TERM_ERR;
        protected System.Web.UI.WebControls.Label lblAVERAGE_PRICE;
        protected ddscControlLibrary.SubmitButtonCtrl btnSearch;
        protected System.Web.UI.WebControls.Label lblNOTE;
        protected ddscControlLibrary.InputBoxCtrl txtNOTE;
        protected System.Web.UI.WebControls.Label lblCLASS_DESCRIPTION;
        protected System.Web.UI.WebControls.Label lblMINNUM_QTY;
        protected ddscControlLibrary.InputBoxCtrl txtMINNUM_QTY;
        protected System.Web.UI.WebControls.Label lblCLERK2;
        protected System.Web.UI.WebControls.Label lblCLERK_TEL;
        protected ddscControlLibrary.InputBoxCtrl txtCLERK_TEL;
        protected System.Web.UI.WebControls.Label lblADVISED_PRICE_ERR;
        protected System.Web.UI.WebControls.Label lblDUTY_FREE_PRICE_ERR;
        protected System.Web.UI.WebControls.Label lblAVERAGE_PRICE_ERR;
        protected System.Web.UI.WebControls.DropDownList drpCURRENCY_TYPE;
        protected ddscControlLibrary.InputBoxCtrl txtCLERK;
        protected ddscControlLibrary.DateCtrl txtEXP_DATE;
        protected System.Web.UI.HtmlControls.HtmlInputHidden hidCODE;
        protected System.Web.UI.WebControls.DropDownList drpVENDOR_KIND;
        protected System.Web.UI.WebControls.Label lblQUOTATION_VALID_DATE;
        protected ddscControlLibrary.DateCtrl txtQUOTATION_VALID_DATE;
        protected System.Web.UI.WebControls.Label lblMATERIAL_CLASS1;
        protected System.Web.UI.WebControls.Label lblMATERIAL_CLASS;
        protected System.Web.UI.HtmlControls.HtmlInputHidden hidTYPE;
        protected System.Web.UI.HtmlControls.HtmlTableRow SFLAG;
        protected System.Web.UI.WebControls.Label lblORDER_UNIT;
        protected ddscControlLibrary.InputBoxCtrl txtDESCRIPTION1;
        protected ddscControlLibrary.InputBoxCtrl txtDESCRIPTION2;
        protected ddscControlLibrary.InputBoxCtrl txtDESCRIPTION3;
        protected System.Web.UI.WebControls.Label lblPRINTPAGE;
        protected ddscControlLibrary.InputBoxCtrl txtDELIVERY_TERM;
        protected System.Web.UI.WebControls.Label lblDELIVERY_TERM_DESC;
        protected System.Web.UI.WebControls.DropDownList drpADVISED_CURRENCY_TYPE;
        protected System.Web.UI.WebControls.DropDownList drpDUTY_FREE_CURRENCY_TYPE;
        protected System.Web.UI.WebControls.DropDownList drpAVERAGE_CURRENCY_TYPE;
        protected ddscControlLibrary.InputBoxCtrl txtADVISED_PRICE_T;
        protected System.Web.UI.WebControls.DropDownList drpADVISED_T_CURRENCY_TYPE;
        protected System.Web.UI.WebControls.Label lblQUOTATION_VALID_DATE_ERR;
        protected System.Web.UI.WebControls.Label lblPROD_INFO_CHINESE;
        protected ddscControlLibrary.InputBoxCtrl txtPROD_INFO_CHINESE;
        protected System.Web.UI.WebControls.Label lblPROD_INFO_ENGLISH;
        protected ddscControlLibrary.InputBoxCtrl txtPROD_INFO_ENGLISH;
        protected System.Web.UI.WebControls.Label lblPROD_SPEC_CHINESE;
        protected ddscControlLibrary.InputBoxCtrl txtPROD_SPEC_CHINESE;
        protected System.Web.UI.WebControls.Label lblPROD_SPEC_ENGLISH;
        protected ddscControlLibrary.InputBoxCtrl txtPROD_SPEC_ENGLISH;
        protected System.Web.UI.WebControls.DropDownList drpBRAND_ID;
        protected System.Web.UI.WebControls.Label Label3;
        protected System.Web.UI.WebControls.Label lblBRAND1_ID;
        protected System.Web.UI.WebControls.Label lblCHINESE_SHORTNAME;
        protected System.Web.UI.WebControls.Label lblENGLISH_SHORTNAME;
        protected ddscControlLibrary.InputBoxCtrl txtCHINESE_SHORTNAME;
        protected ddscControlLibrary.InputBoxCtrl txtENGLISH_SHORTNAME;
        protected System.Web.UI.WebControls.Label lblENGLISH_SHORTNAME_ERR;
        protected System.Web.UI.WebControls.Label lblUPLOAD_DESC;
        protected System.Web.UI.WebControls.Label lblDELIVERY_DESC;

        //注意: 下列預留位置宣告是 Web Form 設計工具需要的項目。
        //請勿刪除或移動它。
        private System.Object designerPlaceholderDeclaration;

        private void Page_Init(System.Object sender, System.EventArgs e)
        {
            //CODEGEN: 此為 Web Form 設計工具所需的方法呼叫
            //請勿使用程式碼編輯器進行修改。
            InitializeComponent();
        }

        #endregion

        #region 呼叫後端method
        //查詢 code
        public DataSet Query_Serial(string code)
        {
            DataSet dsReturn = default(DataSet);
            dbAccess dba = new dbAccess();
            ArrayList m_arrParam = new ArrayList();
            try
            {

                // 查詢資料總筆數之 sql command
                StringBuilder sb = new StringBuilder();
                sb.Append("Select nvl(max(SERIAL_NO),0) as SERIAL_NO ");
                sb.Append("From B2B_MATERIAL_IMAGE_SEQUENCE ");
                //sb.Append("Where CODE = \'" + code.Trim() + "\' ");
                sb.Append("Where CODE = :CODE ");

                sb.Append(" order by SERIAL_NO");

                // DataTable Name
                string dtName = "BAS_MATERIAL_IMAGE_SEQUENCE";

                // Sql command
                string sqlCommands = sb.ToString();

                m_arrParam.Add(dba.GetOracleParam(":CODE", code.Trim()));
                // create database access object


                //dsReturn = dba.runExecuteQuery(dtName, sqlCommands);

                dsReturn = dba.runExecuteQuery(dtName, sqlCommands, m_arrParam);

            }
            catch (Exception ex)
            {
                // create return object (DataSet)
                dsReturn = new DataSet("Query_Serial");
                dsReturn.Tables.Add(createErrorTable(ex.Message));

            }

            return dsReturn;
        }

        private DataTable createErrorTable(string mError)
        {

            dbReturnInfo dbInfo = new dbReturnInfo("info");
            dbInfo.AddNewRow();
            dbInfo.setReturnDataValue("F", System.Convert.ToString(999), 0, mError);
            return dbInfo.getReturnDataTable();
        }

        private bool getCURRENCY_TYPE()
        {
            bool result = false;
            int i;
            try
            {
                // 將資料寫入下拉式選單
                DataSet ds = drpCURRENCY_TYPE_NO();
                if (!(ds == null) && ds.Tables.Count > 0)
                {
                    if (!(ds == null) && ds.Tables[0].Rows[0]["ReturnCode"] != "100" && ds.Tables[0].Rows[0]["ReturnCode"] != "999")
                    {
                        drpCURRENCY_TYPE.DataSource = ds.Tables["BAS_CURRENCY"];
                        drpCURRENCY_TYPE.DataTextField = "DESCRIPTION";
                        drpCURRENCY_TYPE.DataValueField = "CURRENCY_TYPE";
                        drpCURRENCY_TYPE.DataBind();
                        drpAVERAGE_CURRENCY_TYPE.DataSource = ds.Tables["BAS_CURRENCY"];
                        drpAVERAGE_CURRENCY_TYPE.DataTextField = "DESCRIPTION";
                        drpAVERAGE_CURRENCY_TYPE.DataValueField = "CURRENCY_TYPE";
                        drpAVERAGE_CURRENCY_TYPE.DataBind();
                        drpADVISED_CURRENCY_TYPE.DataSource = ds.Tables["BAS_CURRENCY"];
                        drpADVISED_CURRENCY_TYPE.DataTextField = "DESCRIPTION";
                        drpADVISED_CURRENCY_TYPE.DataValueField = "CURRENCY_TYPE";
                        drpADVISED_CURRENCY_TYPE.DataBind();
                        //joe add 淑宜修改案
                        drpADVISED_T_CURRENCY_TYPE.DataSource = ds.Tables["BAS_CURRENCY"];
                        drpADVISED_T_CURRENCY_TYPE.DataTextField = "DESCRIPTION";
                        drpADVISED_T_CURRENCY_TYPE.DataValueField = "CURRENCY_TYPE";
                        drpADVISED_T_CURRENCY_TYPE.DataBind();
                        //joe add
                        drpDUTY_FREE_CURRENCY_TYPE.DataSource = ds.Tables["BAS_CURRENCY"];
                        drpDUTY_FREE_CURRENCY_TYPE.DataTextField = "DESCRIPTION";
                        drpDUTY_FREE_CURRENCY_TYPE.DataValueField = "CURRENCY_TYPE";
                        drpDUTY_FREE_CURRENCY_TYPE.DataBind();


                        drpAVERAGE_CURRENCY_TYPE.Items.Insert(0, new ListItem("", ""));
                        drpCURRENCY_TYPE.Items.Insert(0, new ListItem("", ""));
                        drpADVISED_CURRENCY_TYPE.Items.Insert(0, new ListItem("", ""));
                        drpDUTY_FREE_CURRENCY_TYPE.Items.Insert(0, new ListItem("", ""));

                    }
                    else
                    {
                        drpAVERAGE_CURRENCY_TYPE.Items.Insert(0, new ListItem("", ""));
                        drpCURRENCY_TYPE.Items.Insert(0, new ListItem("", ""));
                        drpADVISED_CURRENCY_TYPE.Items.Insert(0, new ListItem("", ""));
                        drpDUTY_FREE_CURRENCY_TYPE.Items.Insert(0, new ListItem("", ""));
                    }
                }
            }
            catch (Exception ex)
            {
                showException(ex.Message);
            }
            finally
            {
            }
            return result;
        }

        public DataSet drpCURRENCY_TYPE_NO()
        {
            DataSet dsReturn = default(DataSet);

            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("select CURRENCY_TYPE,(CURRENCY_TYPE||\'-\'||DESCRIPTION)DESCRIPTION from BAS_CURRENCY  order by CURRENCY_TYPE  ");
                string dtName = "BAS_CURRENCY";
                string sqlCommands = sb.ToString();
                dbAccess dba = new dbAccess();
                dsReturn = dba.runExecuteQuery(dtName, sqlCommands);
            }
            catch (Exception ex)
            {
                dsReturn = new DataSet("BAS_CURRENCY");
                dsReturn.Tables.Add(createErrorTable(ex.Message));
            }
            return dsReturn;
        }

        private bool getCLASS()
        {
            bool result = false;
            int i;
            try
            {
                DataSet ds = VND_B2B_CLASS();
                // 將資料寫入下拉式選單
                if (Session["langauage"] == "zh-tw")
                {

                    if (!(ds == null) && ds.Tables.Count > 0)
                    {
                        if (!(ds == null) && ds.Tables[0].Rows[0]["ReturnCode"] != "100" && ds.Tables[0].Rows[0]["ReturnCode"] != "999")
                        {
                            drpVENDOR_KIND.DataSource = ds.Tables["VND_B2B_CLASS"];
                            drpVENDOR_KIND.DataTextField = "DESCRIPTION_CHINESE";
                            drpVENDOR_KIND.DataValueField = "B2B_CLASS_CODE";
                            drpVENDOR_KIND.DataBind();
                        }
                        else
                        {
                            drpVENDOR_KIND.Items.Insert(0, new ListItem("", ""));

                        }

                    }
                }
                else
                {
                    if (!(ds == null) && ds.Tables.Count > 0)
                    {
                        if (!(ds == null) && ds.Tables[0].Rows[0]["ReturnCode"] != "100" && ds.Tables[0].Rows[0]["ReturnCode"] != "999")
                        {
                            drpVENDOR_KIND.DataSource = ds.Tables["VND_B2B_CLASS"];
                            drpVENDOR_KIND.DataTextField = "DESCRIPTION_ENGLISH";
                            drpVENDOR_KIND.DataValueField = "B2B_CLASS_CODE";
                            drpVENDOR_KIND.DataBind();

                        }
                        else
                        {
                            drpVENDOR_KIND.Items.Insert(0, new ListItem("", ""));

                        }

                    }

                }

            }
            catch (Exception ex)
            {
                showException(ex.Message);
            }
            finally
            {
            }
            return result;
        }
        public DataSet VND_B2B_CLASS()
        {
            DataSet dsReturn = default(DataSet);
            try
            {
                // 查詢資料總筆數之 sql command


                StringBuilder sb = new StringBuilder();
                sb.Append("Select  B2B_CLASS_CODE,(B2B_CLASS_CODE ||\'-\'||DESCRIPTION_CHINESE)DESCRIPTION_CHINESE,(B2B_CLASS_CODE ||\'-\'||DESCRIPTION_ENGLISH)DESCRIPTION_ENGLISH  From VND_B2B_CLASS Where status = \'1\' ");

                // DataTable Name
                string dtName = "VND_B2B_CLASS";
                // Sql command
                string sqlCommands = sb.ToString();
                // create database access object
                dbAccess dba = new dbAccess();
                dsReturn = dba.runExecuteQuery(dtName, sqlCommands);
            }
            catch (Exception ex)
            {
                dsReturn = new DataSet("VND_B2B_CLASS");
                dsReturn.Tables.Add(createErrorTable(ex.Message));
            }

            return dsReturn;
        }


        private void clearControl()
        {
            VENDOR OnUser = GetLoginUser();
            if (this.Request["action_type"].ToString() == "ADD")
            {
                this.txtCODE_SEQ.Text = "";
                this.txtENGLISH_SHORTNAME.Text = "";
                this.txtENGLISH_FULLNAME.Text = "";
                this.txtCHINESE_SHORTNAME.Text = "";
                this.txtCHINESE_FULLNAME.Text = "";
                this.txtLEAD_TIME.Text = "";
                this.txtEXP_DATELINE.Text = "";
                this.txtSUPPLY_PRICE.Text = "";
                this.txtCOEFFICIENT.Text = "";
                this.txtPACK_DETAIL.Text = "";
                this.txtDIMENSION_L.Text = "";
                this.txtDIMENSION_H.Text = "";
                this.txtDIMENSION_W.Text = "";
                this.txtGROSS_WEIGHT.Text = "";
            }
            else
            {
                this.txtCODE_SEQ.Text = "";
                this.txtENGLISH_SHORTNAME.Text = "";
                this.txtENGLISH_FULLNAME.Text = "";
                this.txtCHINESE_SHORTNAME.Text = "";
                this.txtCHINESE_FULLNAME.Text = "";
            }

        }

        private void getDELIVERY_TERM()
        {
            //Dim result As Boolean = False
            //Dim i As Integer
            //Try
            //    Dim DELIVERY_TERM_EN(7) As String
            //    DELIVERY_TERM_EN(0) = "FOB_Seaport"
            //    DELIVERY_TERM_EN(1) = "CIF_keeling"
            //    DELIVERY_TERM_EN(2) = "Ex_Work"
            //    DELIVERY_TERM_EN(3) = "CIF_長榮航空保稅倉庫"
            //    DELIVERY_TERM_EN(4) = "長榮航空保稅大樓倉庫"
            //    DELIVERY_TERM_EN(5) = "長榮航空南崁運航大樓倉庫"
            //    DELIVERY_TERM_EN(6) = "FOB_Airport"
            //    DELIVERY_TERM_EN(7) = "CIF_CKS_Airport"
            //    Dim DELIVERY_TERM_TW(7) As String
            //    DELIVERY_TERM_TW(0) = "FOB_Seaport"
            //    DELIVERY_TERM_TW(1) = "CIF_keeling"
            //    DELIVERY_TERM_TW(2) = "Ex_Work"
            //    DELIVERY_TERM_TW(3) = "CIF_長榮航空保稅倉庫"
            //    DELIVERY_TERM_TW(4) = "長榮航空保稅大樓倉庫"
            //    DELIVERY_TERM_TW(5) = "長榮航空南崁運航大樓倉庫"
            //    DELIVERY_TERM_TW(6) = "FOB_Airport"
            //    DELIVERY_TERM_TW(7) = "CIF_CKS_Airport"
            //    ' 將資料寫入下拉式選單

            //    If Session("langauage") = "zh-tw" Then
            //        drpDELIVERY_TERM.Items.Insert(0, New ListItem("Select", ""))
            //        For i = 0 To 7
            //            drpDELIVERY_TERM.Items.Insert(i + 1, New ListItem(DELIVERY_TERM_TW(i), DELIVERY_TERM_TW(i)))
            //        Next
            //    Else
            //        drpDELIVERY_TERM.Items.Insert(0, New ListItem("Select", ""))
            //        For i = 0 To 7
            //            drpDELIVERY_TERM.Items.Insert(i + 1, New ListItem(DELIVERY_TERM_EN(i), DELIVERY_TERM_EN(i)))
            //        Next
            //    End If


            //Catch ex As Exception
            //    showException(ex.Message)
            //Finally
            //End Try
            //Return result
            DataSet ds = default(DataSet);
            try
            {

                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT CODE_SDES,CODE_DESC FROM BAS_SUB_COMMON_TYPE WHERE CODE_TYPE=\'DT\'");

                // DataTable Name
                string dtName = "VND_DELIVERY_TERM";
                // Sql command
                string sqlCommands = sb.ToString();
                // create database access object
                dbAccess dba = new dbAccess();
                ds = dba.runExecuteQuery(dtName, sqlCommands);

                if (!(ds == null) && ds.Tables.Count > 0)
                {
                    if (!(ds == null) && ds.Tables[0].Rows[0]["ReturnCode"] != "100" && ds.Tables[0].Rows[0]["ReturnCode"] != "999")
                    {
                        drpDELIVERY_TERM.DataSource = ds.Tables["VND_DELIVERY_TERM"];
                        drpDELIVERY_TERM.DataTextField = "CODE_DESC";
                        drpDELIVERY_TERM.DataValueField = "CODE_SDES";
                        drpDELIVERY_TERM.DataBind();
                    }
                    else
                    {
                        drpDELIVERY_TERM.Items.Insert(0, new ListItem("", ""));

                    }

                }
            }
            catch (Exception ex)
            {
                ds = new DataSet("VND_DELIVERY_TERM");
                ds.Tables.Add(createErrorTable(ex.Message));
            }
        }

        private bool getPAYMENT_TERM(string VENDOR_TYPE)
        {
            bool result = false;
            int i;
            try
            {
                // 將資料寫入下拉式選單
                DataSet ds = PAYMENT_TERM_NO(VENDOR_TYPE);
                if (!(ds == null) && ds.Tables.Count > 0)
                {
                    if (!(ds == null) && ds.Tables[0].Rows[0]["ReturnCode"] != "100" && ds.Tables[0].Rows[0]["ReturnCode"] != "999")
                    {
                        drpPAYMENT_TERM_NO.DataSource = ds.Tables["BAS_PAYMENT_TERM"];
                        drpPAYMENT_TERM_NO.DataTextField = "DESCRIPTION";
                        drpPAYMENT_TERM_NO.DataValueField = "PAYMENT_TERM_NO";
                        drpPAYMENT_TERM_NO.DataBind();
                    }
                    else
                    {
                        drpPAYMENT_TERM_NO.Items.Insert(0, new ListItem("", ""));

                    }
                    drpPAYMENT_TERM_NO.Items.Insert(0, new ListItem("Select", ""));
                }
            }
            catch (Exception ex)
            {
                showException(ex.Message);
            }
            finally
            {
            }
            return result;
        }

        public DataSet PAYMENT_TERM_NO(string VENDOR_TYPE)
        {
            DataSet dsReturn = default(DataSet);
            dbAccess dba = new dbAccess();
            ArrayList m_arrParam = new ArrayList();
            try
            {
                // 查詢資料總筆數之 sql command
                StringBuilder sb = new StringBuilder();
                //sb.Append("Select PAYMENT_TERM_NO,(PAYMENT_TERM_NO||\'-\'||DESCRIPTION) DESCRIPTION From BAS_PAYMENT_TERM  where country_kind in(\'A\',\'" + VENDOR_TYPE + "\') order by PAYMENT_TERM_NO  ");
                sb.Append("Select PAYMENT_TERM_NO,(PAYMENT_TERM_NO||\'-\'||DESCRIPTION) DESCRIPTION From BAS_PAYMENT_TERM  where country_kind in(\'A\',:VENDORTYPE) order by PAYMENT_TERM_NO  ");
                // DataTable Name
                string dtName = "BAS_PAYMENT_TERM";
                // Sql command
                string sqlCommands = sb.ToString();
                // create database access object

                m_arrParam.Add(dba.GetOracleParam(":VENDORTYPE", VENDOR_TYPE));
                //dsReturn = dba.runExecuteQuery(dtName, sqlCommands);
                dsReturn = dba.runExecuteQuery(dtName, sqlCommands, m_arrParam);

            }
            catch (Exception ex)
            {
                // create return object (DataSet)
                dsReturn = new DataSet("BAS_PAYMENT_TERM");
                dsReturn.Tables.Add(createErrorTable(ex.Message));
            }

            return dsReturn;
        }

        public DataSet Query_Material_Type(com.ddsc.common.ddscDataSet p_ddscDt)
        {
            DataSet dsReturn = default(DataSet);
            DataSet ds = p_ddscDt.getDataSet();
            dbAccess dba = new dbAccess();
            ArrayList m_arrParam = new ArrayList();
            string MATERIAL_TYPE = "";
            try
            {

                // 查詢資料總筆數之 sql command
                StringBuilder sb = new StringBuilder();
                MATERIAL_TYPE = ds.Tables[0].Rows[1]["MATERIAL_TYPE"].ToString();
                sb.Append("Select distinct CLASS,(CLASS||\' - \'||CLASS_NAME)CLASS_NAME From BAS_MATERIAL_CLASS ");
                //sb.Append("Where class_level = \'1\' and class not in (\'A\') and  " + MATERIAL_TYPE + "");
                sb.Append("Where class_level = \'1\' and class not in (\'A\') and  :MATERIALTYPE");

                // DataTable Name
                string dtName = "BAS_MATERIAL_CLASS";

                // Sql command
                string sqlCommands = sb.ToString();

                m_arrParam.Add(dba.GetOracleParam(":MATERIALTYPE", MATERIAL_TYPE));
                // create database access object
                //dbAccess dba = new dbAccess();
                //dsReturn = dba.runExecuteQuery(dtName, sqlCommands);
                dsReturn = dba.runExecuteQuery(dtName, sqlCommands, m_arrParam);



            }
            catch (Exception ex)
            {
                // create return object (DataSet)
                dsReturn = new DataSet("BAS_MATERIAL_CLASS");
                dsReturn.Tables.Add(createErrorTable(ex.Message));



            }

            return dsReturn;
        }

        private void CLEAN()
        {
            this.txtCODE_SEQ.Text = "";
            this.chkDEL1.Checked = false;
            this.chkDEL2.Checked = false;
            this.chkDEL3.Checked = false;
            this.txtENGLISH_SHORTNAME.Text = "";
            this.txtENGLISH_FULLNAME.Text = "";
            this.txtCHINESE_SHORTNAME.Text = "";
            this.txtCHINESE_FULLNAME.Text = "";
            this.rdoMATERIAL_TYPE.SelectedIndex = 0;
            this.drpVENDOR_KIND.SelectedIndex = 0;
            this.rdoCONSIGNED.SelectedIndex = 0;
            this.txtLEAD_TIME.Text = "";
            this.txtEXP_DATELINE.Text = "";
            this.drpPACKAGE_UNIT.SelectedIndex = 0;
            this.txtSUPPLY_PRICE.Text = "";
            this.txtCOEFFICIENT.Text = "";
            this.txtPACK_DETAIL.Text = "";
            this.txtDIMENSION_L.Text = "";
            this.txtDIMENSION_H.Text = "";
            this.txtDIMENSION_W.Text = "";
            this.txtGROSS_WEIGHT.Text = "";
            this.txtDESCRIPTION1.Text = "";
            this.txtDESCRIPTION2.Text = "";
            this.txtDESCRIPTION3.Text = "";
            //Update S8970025
            this.txtADVISED_PRICE.Text = "";
            this.txtDUTY_FREE_PRICE.Text = "";
            this.txtAVERAGE_PRICE.Text = "";
            this.drpCURRENCY_TYPE.SelectedIndex = 0;
            this.txtMINNUM_QTY.Text = "";
            this.txtNOTE.Text = "";
            this.txtQUOTATION_VALID_DATE.Text = "";
            this.txtCLERK.Text = "";
            this.txtCLERK_TEL.Text = "";
            this.drpPAYMENT_TERM_NO.SelectedIndex = 0;
            this.drpDELIVERY_TERM.SelectedIndex = 0; //20100901 JAFF DISCARD MARK
            this.txtSEAPORT.Text = ""; //20100901 JAFF ADD
            //Me.txtDELIVERY_TERM.Text = ""          '20100901 JAFF MARK

        }

        #endregion

        private void Page_Load(System.Object sender, System.EventArgs e)
        {
            //在這裡放置使用者程式碼以初始化網頁
            // 載入權限資料 (從 session 中取得)
            System.DBNull DBNull;
            this.btnSave.Click += btnSAVE_Click;
            this.btnDel.Click += btnDEL_Click;
            try
            {
                dbAccess dba = new dbAccess();
                ArrayList m_arrParam = new ArrayList();
                if (Page.Request["action_type"].ToUpper() != "SMAS")
                {
                    if (Session["langauage"] == "zh-tw")
                    {
                        this.hidlangauage.Value = "zh-tw";
                    }
                    else
                    {
                        this.hidlangauage.Value = "zh-en";
                    }
                    if (Page.Request["action_type"].ToUpper() == "BULLETIN")
                    {
                        txtPURCHASE_NO.Text = Server.HtmlEncode(Page.Request["PURCHASE_NO"]);
                    }

                    if (!Page.IsPostBack)
                    {
                        string action = "ADD";
                        getDELIVERY_TERM();

                        getCURRENCY_TYPE();
                        VENDOR LoginUser = GetLoginUser();
                        getPAYMENT_TERM(LoginUser.VENDOR_TYPE);

                        if (((string)(Page.Request["action_type"].ToUpper()) == "ADD") || ((string)(Page.Request["action_type"].ToUpper()) == "BULLETIN"))
                        {
                            // 新增模式

                            //P3109M0050 將新增幣別設定為TWD
                            this.drpCURRENCY_TYPE.SelectedValue = "TWD";
                            this.drpADVISED_CURRENCY_TYPE.SelectedValue = "TWD";
                            this.drpADVISED_T_CURRENCY_TYPE.SelectedValue = "TWD";
                            this.drpAVERAGE_CURRENCY_TYPE.SelectedValue = "TWD";
                            this.drpDUTY_FREE_CURRENCY_TYPE.SelectedValue = "TWD";


                            this.hidTYPE.Value = "S";
                            getCLASS();
                            getBRAND("");
                            //Me.txtCURRENCY_TYPE.Text = LoginUser.CURRENCY_TYPE
                            this.btnDel.Visible = false;
                            this.chkDEL1.Enabled = false;
                            this.chkDEL2.Enabled = false;
                            this.chkDEL3.Enabled = false;
                            this.btnVIEW1.Visible = false;
                            this.btnVIEW2.Visible = false;
                            this.btnVIEW3.Visible = false;
                            // Me.txtCURRENCY_TYPE.Text = LoginUser.CURRENCY_TYPE
                        }
                        else if ((string)(Page.Request["action_type"].ToUpper()) == "UPD")
                        {
                            // 修改模式
                            this.btnDel.Visible = false;
                            string strPkey = Page.Request["CODE"];
                            getBRAND("");
                            //至db 查詢正在修改的這一筆
                            //string SelectCommand = string.Format("select A.*,B.*,B.EXP_DATE as END_DATE from  B2B_MATERIAL A ,B2B_SUPPLY B where A.CODE=B.CODE(+) AND A.CODE= \'{0}\'", strPkey);
                            string SelectCommand = "SELECT A.*,B.*,B.EXP_DATE as END_DATE , C.PAYMENT_TERM_NO || '-' || C.DESCRIPTION AS PAYMENT_TERM_DESCRIPTION FROM  B2B_MATERIAL A ,B2B_SUPPLY B,BAS_PAYMENT_TERM C WHERE B.PAYMENT_TERM_NO = C.PAYMENT_TERM_NO AND A.CODE=B.CODE(+) AND A.CODE= :strPkey";
                            DataBase DataBase = new DataBase();
                            DataSet ds = default(DataSet);

                            m_arrParam.Add(dba.GetOracleParam(":strPkey", strPkey));

                            ds = DataBase.Query_CLASS(SelectCommand, "B2B_MATERIAL", m_arrParam);
                            //ds = dba.runExecuteQuery("B2B_MATERIAL",SelectCommand,m_arrParam );

                            int Row = 0;

                            if (!(ds == null) && ds.Tables["info"].Rows[0]["ReturnCode"] != "100" && ds.Tables["info"].Rows[0]["ReturnCode"] != "999")
                            {
                                Row = System.Convert.ToInt32(ds.Tables["B2B_MATERIAL"].Rows.Count - 1);
                                txtPURCHASE_NO.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PURCHASE_NO"].ToString());
                                txtCODE_SEQ.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CODE"].ToString());
                                this.txtENGLISH_SHORTNAME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ENGLISH_SHORTNAME"].ToString());
                                this.txtENGLISH_FULLNAME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ENGLISH_FULLNAME"].ToString());
                                this.txtCHINESE_SHORTNAME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CHINESE_SHORTNAME"].ToString());
                                this.txtCHINESE_FULLNAME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CHINESE_FULLNAME"].ToString());
                                //Leo Add 20090729 增加五個欄位
                                this.txtPROD_INFO_CHINESE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PROD_INFO_CHINESE"].ToString());
                                this.txtPROD_INFO_ENGLISH.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PROD_INFO_ENGLISH"].ToString());
                                this.txtPROD_SPEC_CHINESE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PROD_SPEC_CHINESE"].ToString());
                                this.txtPROD_SPEC_ENGLISH.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PROD_SPEC_ENGLISH"].ToString());
                                this.drpBRAND_ID.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["BRAND_ID"].ToString());


                                //Leo add end


                                this.rdoMATERIAL_TYPE.SelectedValue = ds.Tables["B2B_MATERIAL"].Rows[Row]["MATERIAL_TYPE"].ToString();
                                this.hidTYPE.Value = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["MATERIAL_TYPE"].ToString());
                                getCLASS();
                                this.drpVENDOR_KIND.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CLASS"].ToString());

                                this.rdoCONSIGNED.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CONSIGNED"].ToString());
                                this.txtLEAD_TIME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["LEAD_TIME"].ToString());
                                this.txtEXP_DATELINE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["EXP_DATE"].ToString());
                                this.drpPACKAGE_UNIT.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PACKAGE_UNIT"].ToString());
                                this.txtSUPPLY_PRICE.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["SUPPLY_PRICE"].ToString()));
                                hidCODE.Value = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["SUPPLY_PRICE"].ToString());
                                this.txtCOEFFICIENT.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["COEFFICIENT"].ToString());
                                this.txtPACK_DETAIL.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PACK_DETAIL"].ToString());

                                this.txtDIMENSION_L.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DIMENSION_L"].ToString()));
                                this.txtDIMENSION_H.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DIMENSION_H"].ToString()));
                                this.txtDIMENSION_W.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DIMENSION_W"].ToString()));
                                this.txtGROSS_WEIGHT.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["GROSS_WEIGHT"].ToString()));

                                this.txtMINNUM_QTY.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["MINNUM_QTY"].ToString());

                                this.chkDEL1.Enabled = false;
                                this.chkDEL2.Enabled = false;
                                this.chkDEL3.Enabled = false;
                                this.txtDESCRIPTION1.Enabled = false;
                                this.txtDESCRIPTION2.Enabled = false;
                                this.txtDESCRIPTION3.Enabled = false;

                                //Update S8970025

                                string DELIVERY_TERM = ds.Tables["B2B_MATERIAL"].Rows[0]["DELIVERY_TERM"].ToString();
                                //20100901 JAFF ADD----------------------
                                if (DELIVERY_TERM.IndexOf("_") != -1) //判斷是否有分格符號
                                {
                                    Array TERM = DELIVERY_TERM.Split('_');
                                    if (this.drpDELIVERY_TERM.Items.IndexOf(this.drpDELIVERY_TERM.Items.FindByValue(TERM.GetValue(0).ToString())) != -1) //判斷抓出的TERM是否有在下拉選單內
                                    {
                                        this.drpDELIVERY_TERM.SelectedIndex = this.drpDELIVERY_TERM.Items.IndexOf(this.drpDELIVERY_TERM.Items.FindByValue(TERM.GetValue(0).ToString()));
                                        this.txtSEAPORT.Text = TERM.GetValue(1).ToString();
                                    }
                                    else
                                    {
                                        this.drpDELIVERY_TERM.Items.Insert(0, new ListItem(TERM.GetValue(0).ToString(), "NULL"));
                                        this.txtSEAPORT.Text = TERM.GetValue(1).ToString();
                                    }
                                }
                                else
                                {
                                    this.drpDELIVERY_TERM.Items.Insert(0, "");
                                    this.txtSEAPORT.Text = DELIVERY_TERM; //若沒有分格符號就將整個值塞給這個欄位
                                }
                                //----------------------------------------
                                //If DELIVERY_TERM.Length > 11 Then
                                //    If DELIVERY_TERM.Substring(0, 11) = "FOB_Seaport" Then

                                //        Me.txtSEAPORT.Text = DELIVERY_TERM.Substring(11, DELIVERY_TERM.Length - 11)
                                //        DELIVERY_TERM = "FOB_Seaport"
                                //    End If
                                //End If

                                //If Me.drpDELIVERY_TERM.Items.IndexOf(Me.drpDELIVERY_TERM.Items.FindByValue(DELIVERY_TERM)) <> -1 Then
                                //    Me.drpDELIVERY_TERM.SelectedIndex = Me.drpDELIVERY_TERM.Items.IndexOf(Me.drpDELIVERY_TERM.Items.FindByValue(DELIVERY_TERM))
                                //Else
                                //    Me.drpDELIVERY_TERM.Items.Insert(0, New ListItem(DELIVERY_TERM, "NULL"))
                                //End If
                                //Me.drpDELIVERY_TERM.SelectedValue = DELIVERY_TERM
                                //Me.txtDELIVERY_TERM.Text = DELIVERY_TERM '20100901 JAFF REMARK

                                string PAYMENT_TERM_NO = ds.Tables["B2B_MATERIAL"].Rows[0]["PAYMENT_TERM_NO"].ToString();
                                if (this.drpPAYMENT_TERM_NO.Items.IndexOf(this.drpPAYMENT_TERM_NO.Items.FindByValue(PAYMENT_TERM_NO)) != -1)
                                {
                                    this.drpPAYMENT_TERM_NO.SelectedIndex = this.drpPAYMENT_TERM_NO.Items.IndexOf(this.drpPAYMENT_TERM_NO.Items.FindByValue(PAYMENT_TERM_NO));
                                }
                                else
                                {
                                    string PAYMENT_TERM_DESCRIPTION = ds.Tables["B2B_MATERIAL"].Rows[0]["PAYMENT_TERM_DESCRIPTION"].ToString();
                                    this.drpPAYMENT_TERM_NO.Items.Insert(0, new ListItem(PAYMENT_TERM_DESCRIPTION, PAYMENT_TERM_NO));
                                }
                                this.drpPAYMENT_TERM_NO.SelectedValue = PAYMENT_TERM_NO;

                                this.txtADVISED_PRICE.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ADVISED_PRICE"].ToString()));
                                // JOE ADD P3108M0777
                                if (ds.Tables["B2B_MATERIAL"].Rows[Row]["ADVISED_PRICE"].GetType().ToString() != "System.DBNull")
                                {
                                    double d = Double.Parse(ds.Tables["B2B_MATERIAL"].Rows[0]["ADVISED_PRICE"].ToString());
                                    //this.txtADVISED_PRICE_T.Text = (Math.Round(d * 1.05)).ToString();
                                    this.txtADVISED_PRICE_T.Text = (Math.Round(d * 1.05, 0, MidpointRounding.AwayFromZero)).ToString();
                                    this.drpADVISED_T_CURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ADVISED_CURRENCY_TYPE"].ToString());
                                }


                                this.txtAVERAGE_PRICE.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["AVERAGE_PRICE"].ToString()));
                                this.txtDUTY_FREE_PRICE.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DUTY_FREE_PRICE"].ToString()));
                                this.drpCURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CURRENCY_TYPE"].ToString());
                                this.drpADVISED_CURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ADVISED_CURRENCY_TYPE"].ToString());
                                this.drpAVERAGE_CURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["AVERAGE_CURRENCY_TYPE"].ToString());
                                this.drpDUTY_FREE_CURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DUTY_FREE_CURRENCY_TYPE"].ToString());


                                this.txtNOTE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["NOTE"].ToString());
                                this.txtQUOTATION_VALID_DATE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["QUOTATION_VALID_DATE"].ToString());
                                this.txtCLERK.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CLERK"].ToString());
                                this.txtCLERK_TEL.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CLERK_TEL"].ToString());

                                hidPAYMENT_TERM_NO.Value = this.drpPAYMENT_TERM_NO.SelectedValue;
                                hidCURRENCY_TYPE.Value = this.drpCURRENCY_TYPE.SelectedValue;
                                hidSUPPLY_PRICE.Value = StringFormat(this.txtSUPPLY_PRICE.Text);
                                hidDELIVERY_TERM.Value = this.drpDELIVERY_TERM.SelectedValue + "_" + txtSEAPORT.Text; //20100901 JAFF ADD
                                //hidDELIVERY_TERM.Value = Me.txtDELIVERY_TERM.Text '20100901 JAFF REMARK
                                dbConnection dbac = new dbConnection();
                                OracleConnection myConnection = dbac.getOracleClientConnection();
                                // Dim strSQL As String = String.Format("select serial_no,DESCRIPTION,image from B2B_MATERIAL_IMAGE_SEQUENCE where code='{0}'and status=1 order by serial_no ", strPkey)
                                string strSQL = "select serial_no,DESCRIPTION,image from B2B_MATERIAL_IMAGE_SEQUENCE where code=:code and status=1 order by serial_no ";
                                //P3512S0159-針對B2B網站SCA弱點掃描修正程式============
                                OracleCommand myCommand = new OracleCommand(strSQL, myConnection);
                                myCommand.Parameters.Add(":code", OracleType.VarChar).Value = strPkey;
                                //P3512S0159-針對B2B網站SCA弱點掃描修正程式============

                                OracleDataAdapter MyDA = new OracleDataAdapter(myCommand);
                                DataSet ds1 = new DataSet();
                                MyDA.Fill(ds1);
                                myConnection.Close();
                                myConnection.Dispose();
                                this.btnVIEW1.Disabled = true;
                                this.btnVIEW2.Disabled = true;
                                this.btnVIEW3.Disabled = true;
                                int i = 0;
                                string CODE;
                                string PATH;

                                for (i = 0; i <= ds1.Tables[0].Rows.Count - 1; i++)
                                {
                                    m_arrParam.Clear();
                                    switch (i)
                                    {
                                        case 0:
                                            this.txtPIC_NO1.Text = Server.HtmlEncode(ds1.Tables[0].Rows[i]["serial_no"].ToString());

                                            // string SelectCommand_d_1 = string.Format("select DESCRIPTION from B2B_MATERIAL_IMAGE_SEQUENCE where code=\'{0}\'and status=1 and serial_no=\'{1}\'  ", strPkey, ds1.Tables[0].Rows[i]["serial_no"].ToString());
                                            string SelectCommand_d_1 = string.Format("select DESCRIPTION from B2B_MATERIAL_IMAGE_SEQUENCE where code=:strPkey and status=1 and serial_no=:serialNO  ");

                                            m_arrParam.Add(dba.GetOracleParam(":strPkey", strPkey));
                                            m_arrParam.Add(dba.GetOracleParam(":serialNO", ds1.Tables[0].Rows[i]["serial_no"].ToString()));
                                            DataSet dsd_1 = default(DataSet);
                                            dsd_1 = DataBase.Query_CLASS(SelectCommand_d_1, "B2B_MATERIAL_IMAGE_SEQUENCE", m_arrParam);
                                            //DataSet dsd_1 = dba.runExecuteQuery("B2B_MATERIAL_IMAGE_SEQUENCE", SelectCommand_d_1, m_arrParam);

                                            int Rowd_1;
                                            if (!(dsd_1 == null) && dsd_1.Tables["info"].Rows[0]["ReturnCode"] != "100" && dsd_1.Tables["info"].Rows[0]["ReturnCode"] != "999")
                                            {
                                                this.txtDESCRIPTION1.Text = System.Convert.ToString(dsd_1.Tables["B2B_MATERIAL_IMAGE_SEQUENCE"].Rows[Row]["DESCRIPTION"].ToString());
                                            }
                                            // Me.txtDESCRIPTION1.Text = ds1.Tables(0).Rows(i)("DESCRIPTION").ToString()
                                            if (ds1.Tables[0].Rows[i]["image"].ToString() == "")
                                            {
                                                this.btnVIEW1.Disabled = true;
                                                // Me.hidIMAGE1.Value = False
                                            }
                                            else
                                            {
                                                this.btnVIEW1.Disabled = false;
                                                // Me.hidIMAGE1.Value = True
                                            }
                                            this.chkDEL1.Enabled = true;
                                            this.txtDESCRIPTION1.EnableView = false;
                                            this.txtDESCRIPTION1.Enabled = true;
                                            break;
                                        case 1:
                                            this.txtPIC_NO2.Text = Server.HtmlEncode(ds1.Tables[0].Rows[i]["serial_no"].ToString());
                                            //string SelectCommand_d_2 = string.Format("select DESCRIPTION from B2B_MATERIAL_IMAGE_SEQUENCE where code=\'{0}\'and status=1 and serial_no=\'{1}\'  ", strPkey, ds1.Tables[0].Rows[i]["serial_no"].ToString());
                                            string SelectCommand_d_2 = string.Format("select DESCRIPTION from B2B_MATERIAL_IMAGE_SEQUENCE where code=:strPkey and status=1 and serial_no=:serialNO  ");
                                            m_arrParam.Add(dba.GetOracleParam(":strPkey", strPkey));
                                            m_arrParam.Add(dba.GetOracleParam(":serialNO", ds1.Tables[0].Rows[i]["serial_no"].ToString()));

                                            //DataSet dsd_2 = default(DataSet);
                                            //dsd_2 = DataBase.Query_CLASS(SelectCommand_d_2, "B2B_MATERIAL_IMAGE_SEQUENCE");
                                            DataSet dsd_2 = dba.runExecuteQuery("B2B_MATERIAL_IMAGE_SEQUENCE", SelectCommand_d_2, m_arrParam);

                                            int Rowd_2;
                                            if (!(dsd_2 == null) && dsd_2.Tables["info"].Rows[0]["ReturnCode"] != "100" && dsd_2.Tables["info"].Rows[0]["ReturnCode"] != "999")
                                            {
                                                this.txtDESCRIPTION2.Text = System.Convert.ToString(dsd_2.Tables["B2B_MATERIAL_IMAGE_SEQUENCE"].Rows[Row]["DESCRIPTION"].ToString());
                                            }

                                            if (ds1.Tables[0].Rows[i]["image"].ToString() == "")
                                            {
                                                this.btnVIEW2.Disabled = true;
                                            }
                                            else
                                            {
                                                this.btnVIEW2.Disabled = false;
                                            }
                                            this.chkDEL2.Enabled = true;
                                            this.txtDESCRIPTION2.EnableView = false;
                                            this.txtDESCRIPTION2.Enabled = true;
                                            break;
                                        case 2:
                                            this.txtPIC_NO3.Text = Server.HtmlEncode(ds1.Tables[0].Rows[i]["serial_no"].ToString());
                                            //string SelectCommand_d = string.Format("select DESCRIPTION from B2B_MATERIAL_IMAGE_SEQUENCE where code=\'{0}\'and status=1 and serial_no=\'{1}\'  ", strPkey, ds1.Tables[0].Rows[i]["serial_no"].ToString());

                                            string SelectCommand_d = string.Format("select DESCRIPTION from B2B_MATERIAL_IMAGE_SEQUENCE where code=:strPkey and status=1 and serial_no=:serialNO  ");
                                            m_arrParam.Add(dba.GetOracleParam(":strPkey", strPkey));
                                            m_arrParam.Add(dba.GetOracleParam(":serialNO", ds1.Tables[0].Rows[i]["serial_no"].ToString()));

                                            //DataSet dsd = default(DataSet);
                                            //dsd = DataBase.Query_CLASS(SelectCommand_d, "B2B_MATERIAL_IMAGE_SEQUENCE");
                                            DataSet dsd = dba.runExecuteQuery("B2B_MATERIAL_IMAGE_SEQUENCE", SelectCommand_d, m_arrParam);
                                            int Rowd;
                                            if (!(dsd == null) && dsd.Tables["info"].Rows[0]["ReturnCode"] != "100" && dsd.Tables["info"].Rows[0]["ReturnCode"] != "999")
                                            {
                                                this.txtDESCRIPTION3.Text = System.Convert.ToString(dsd.Tables["B2B_MATERIAL_IMAGE_SEQUENCE"].Rows[Row]["DESCRIPTION"].ToString());
                                            }
                                            if (ds1.Tables[0].Rows[i]["image"].ToString() == "")
                                            {
                                                this.btnVIEW3.Disabled = true;
                                            }
                                            else
                                            {
                                                this.btnVIEW3.Disabled = false;
                                            }
                                            this.chkDEL3.Enabled = true;
                                            this.txtDESCRIPTION3.EnableView = false;
                                            this.txtDESCRIPTION3.Enabled = true;
                                            break;
                                    }
                                }
                            }
                            else
                            {
                                showException("對不起! 此筆資料，已被刪除");
                            }
                        }
                        else if ((string)(Page.Request["action_type"].ToUpper()) == "FIND")
                        {
                            // 查詢模式
                            this.chkDEL1.Enabled = false;
                            this.chkDEL2.Enabled = false;
                            this.chkDEL3.Enabled = false;
                            this.btnDel.Visible = false;
                            this.btnSave.Visible = false;
                            string strPkey = Page.Request["CODE"];



                            this.txtENGLISH_SHORTNAME.EnableView = true;
                            this.txtENGLISH_FULLNAME.EnableView = true;
                            this.txtCHINESE_SHORTNAME.EnableView = true;
                            this.txtCHINESE_FULLNAME.EnableView = true;
                            this.rdoMATERIAL_TYPE.Enabled = false;
                            this.drpVENDOR_KIND.Enabled = false;
                            this.rdoCONSIGNED.Enabled = false;
                            this.txtLEAD_TIME.EnableView = true;
                            this.txtEXP_DATELINE.EnableView = true;
                            this.drpPACKAGE_UNIT.Enabled = false;
                            this.txtSUPPLY_PRICE.EnableView = true;
                            this.txtCOEFFICIENT.EnableView = true;
                            this.txtPACK_DETAIL.EnableView = true;
                            this.txtDIMENSION_L.EnableView = true;
                            this.txtDIMENSION_H.EnableView = true;
                            this.txtDIMENSION_W.EnableView = true;
                            this.txtGROSS_WEIGHT.EnableView = true;
                            this.txtPATH1.Disabled = true;
                            this.txtPATH2.Disabled = true;
                            this.txtPATH3.Disabled = true;
                            this.txtDESCRIPTION1.EnableView = true;
                            this.txtDESCRIPTION2.EnableView = true;
                            this.txtDESCRIPTION3.EnableView = true;
                            //Update S8970025
                            this.txtADVISED_PRICE.EnableView = true;
                            this.txtDUTY_FREE_PRICE.EnableView = true;
                            this.txtAVERAGE_PRICE.EnableView = true;
                            this.drpCURRENCY_TYPE.Enabled = false;


                            this.drpADVISED_CURRENCY_TYPE.Enabled = false;
                            this.drpAVERAGE_CURRENCY_TYPE.Enabled = false;
                            this.drpDUTY_FREE_CURRENCY_TYPE.Enabled = false;
                            this.txtMINNUM_QTY.EnableView = true;
                            this.txtNOTE.EnableView = true;
                            this.txtQUOTATION_VALID_DATE.EnableView = true;
                            this.txtCLERK.EnableView = true;
                            this.txtCLERK_TEL.EnableView = true;
                            this.drpPAYMENT_TERM_NO.Enabled = false;
                            this.drpDELIVERY_TERM.Enabled = false;
                            this.txtSEAPORT.EnableView = true; //20100901 JAFF ADD
                            //Me.txtDELIVERY_TERM.Enabled = False '20100901 JAFF REMARK


                            //至db 查詢正在修改的這一筆
                            //string SelectCommand = string.Format("select A.*,B.*,B.EXP_DATE as END_DATE from  B2B_MATERIAL A ,B2B_SUPPLY B where A.CODE=B.CODE(+) AND A.CODE= \'{0}\'", strPkey);
                            string SelectCommand = "SELECT A.*,B.*,B.EXP_DATE as END_DATE , C.PAYMENT_TERM_NO || '-' || C.DESCRIPTION AS PAYMENT_TERM_DESCRIPTION FROM  B2B_MATERIAL A ,B2B_SUPPLY B,BAS_PAYMENT_TERM C WHERE B.PAYMENT_TERM_NO = C.PAYMENT_TERM_NO AND A.CODE=B.CODE(+) AND A.CODE= :strPkey";
                            DataBase DataBase = new DataBase();
                            //DataSet ds = default(DataSet);
                            m_arrParam.Clear();
                            m_arrParam.Add(dba.GetOracleParam(":strPkey", strPkey));
                            DataSet ds = DataBase.Query_CLASS(SelectCommand, "B2B_MATERIAL", m_arrParam);

                            //DataSet ds = dba.runExecuteQuery("B2B_MATERIAL", SelectCommand, m_arrParam);
                            int Row = 0;
                            if (!(ds == null) && ds.Tables["info"].Rows[0]["ReturnCode"] != "100" && ds.Tables["info"].Rows[0]["ReturnCode"] != "999")
                            {
                                Row = System.Convert.ToInt32(ds.Tables["B2B_MATERIAL"].Rows.Count - 1);
                                txtCODE_SEQ.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CODE"].ToString());
                                txtPURCHASE_NO.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PURCHASE_NO"].ToString());
                                this.txtENGLISH_SHORTNAME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ENGLISH_SHORTNAME"].ToString());
                                this.txtENGLISH_FULLNAME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ENGLISH_FULLNAME"].ToString());
                                this.txtCHINESE_SHORTNAME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CHINESE_SHORTNAME"].ToString());
                                this.txtCHINESE_FULLNAME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CHINESE_FULLNAME"].ToString());

                                //Leo Add 20090729 增加五個欄位
                                this.txtPROD_INFO_CHINESE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PROD_INFO_CHINESE"].ToString());
                                this.txtPROD_INFO_ENGLISH.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PROD_INFO_ENGLISH"].ToString());
                                this.txtPROD_SPEC_CHINESE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PROD_SPEC_CHINESE"].ToString());
                                this.txtPROD_SPEC_ENGLISH.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PROD_SPEC_ENGLISH"].ToString());
                                getBRAND(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["BRAND_ID"].ToString()));
                                this.drpBRAND_ID.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["BRAND_ID"].ToString());

                                //Leo add end

                                this.txtMINNUM_QTY.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["MINNUM_QTY"].ToString());

                                this.rdoMATERIAL_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["MATERIAL_TYPE"].ToString());
                                this.hidTYPE.Value = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["MATERIAL_TYPE"].ToString());
                                getCLASS();
                                this.drpVENDOR_KIND.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CLASS"].ToString());
                                this.rdoCONSIGNED.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CONSIGNED"].ToString());
                                this.txtLEAD_TIME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["LEAD_TIME"].ToString());
                                this.txtEXP_DATELINE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["EXP_DATE"].ToString());
                                this.drpPACKAGE_UNIT.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PACKAGE_UNIT"].ToString());
                                this.txtSUPPLY_PRICE.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["SUPPLY_PRICE"].ToString()));
                                this.txtCOEFFICIENT.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["COEFFICIENT"].ToString());
                                this.txtPACK_DETAIL.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PACK_DETAIL"].ToString());
                                this.txtDIMENSION_L.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DIMENSION_L"].ToString()));
                                this.txtDIMENSION_H.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DIMENSION_H"].ToString()));
                                this.txtDIMENSION_W.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DIMENSION_W"].ToString()));
                                this.txtGROSS_WEIGHT.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["GROSS_WEIGHT"].ToString()));
                                //Update S8970025

                                string DELIVERY_TERM = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[0]["DELIVERY_TERM"].ToString());
                                //20100901 JAFF ADD---------------
                                if (DELIVERY_TERM.IndexOf("_") != -1) //判斷是否有分格符號
                                {
                                    Array TERM = DELIVERY_TERM.Split('_');
                                    if (this.drpDELIVERY_TERM.Items.IndexOf(this.drpDELIVERY_TERM.Items.FindByValue(TERM.GetValue(0).ToString())) != -1) //判斷抓出的TERM是否有在下拉選單內
                                    {
                                        this.drpDELIVERY_TERM.SelectedIndex = this.drpDELIVERY_TERM.Items.IndexOf(this.drpDELIVERY_TERM.Items.FindByValue(TERM.GetValue(0).ToString()));
                                        this.txtSEAPORT.Text = TERM.GetValue(1).ToString();
                                    }
                                    else
                                    {
                                        this.drpDELIVERY_TERM.Items.Insert(0, new ListItem(TERM.GetValue(0).ToString(), "NULL"));
                                        this.txtSEAPORT.Text = TERM.GetValue(1).ToString();
                                    }
                                }
                                else
                                {
                                    this.drpDELIVERY_TERM.Items.Insert(0, "");
                                    this.txtSEAPORT.Text = DELIVERY_TERM; //若沒有分格符號就將整個值塞給這個欄位
                                }
                                //------------------------------------
                                //If DELIVERY_TERM.Length > 11 Then
                                //    If DELIVERY_TERM.Substring(0, 11) = "FOB_Seaport" Then

                                //        Me.txtSEAPORT.Text = DELIVERY_TERM.Substring(11, DELIVERY_TERM.Length - 11)
                                //        DELIVERY_TERM = "FOB_Seaport"
                                //    End If
                                //End If

                                //If Me.drpDELIVERY_TERM.Items.IndexOf(Me.drpDELIVERY_TERM.Items.FindByValue(DELIVERY_TERM)) <> -1 Then
                                //    Me.drpDELIVERY_TERM.SelectedIndex = Me.drpDELIVERY_TERM.Items.IndexOf(Me.drpDELIVERY_TERM.Items.FindByValue(DELIVERY_TERM))
                                //Else
                                //    Me.drpDELIVERY_TERM.Items.Insert(0, New ListItem(DELIVERY_TERM, "NULL"))
                                //End If
                                // Me.drpDELIVERY_TERM.SelectedValue = DELIVERY_TERM
                                //Me.txtDELIVERY_TERM.Text = DELIVERY_TERM '20100901 JAFF REMARK
                                string PAYMENT_TERM_NO = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[0]["PAYMENT_TERM_NO"].ToString());
                                if (this.drpPAYMENT_TERM_NO.Items.IndexOf(this.drpPAYMENT_TERM_NO.Items.FindByValue(PAYMENT_TERM_NO)) != -1)
                                {
                                    this.drpPAYMENT_TERM_NO.SelectedIndex = this.drpPAYMENT_TERM_NO.Items.IndexOf(this.drpPAYMENT_TERM_NO.Items.FindByValue(PAYMENT_TERM_NO));
                                }
                                else
                                {
                                    string PAYMENT_TERM_DESCRIPTION = ds.Tables["B2B_MATERIAL"].Rows[0]["PAYMENT_TERM_DESCRIPTION"].ToString();
                                    this.drpPAYMENT_TERM_NO.Items.Insert(0, new ListItem(PAYMENT_TERM_DESCRIPTION, PAYMENT_TERM_NO));
                                }

                                this.drpPAYMENT_TERM_NO.SelectedValue = PAYMENT_TERM_NO;
                                this.txtADVISED_PRICE.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ADVISED_PRICE"].ToString()));

                                // JOE ADD P3108M0777
                                if (ds.Tables["B2B_MATERIAL"].Rows[Row]["ADVISED_PRICE"].GetType().ToString() != "System.DBNull")
                                {
                                    double d = Double.Parse(ds.Tables["B2B_MATERIAL"].Rows[0]["ADVISED_PRICE"].ToString());
                                    //this.txtADVISED_PRICE_T.Text = (Math.Round(d * 1.05)).ToString();
                                    this.txtADVISED_PRICE_T.Text = (Math.Round(d * 1.05, 0, MidpointRounding.AwayFromZero)).ToString();
                                    this.drpADVISED_T_CURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ADVISED_CURRENCY_TYPE"].ToString());
                                }

                                this.txtAVERAGE_PRICE.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["AVERAGE_PRICE"].ToString()));
                                this.txtDUTY_FREE_PRICE.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DUTY_FREE_PRICE"].ToString()));
                                this.drpCURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CURRENCY_TYPE"].ToString());
                                this.drpADVISED_CURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ADVISED_CURRENCY_TYPE"].ToString());
                                this.drpAVERAGE_CURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["AVERAGE_CURRENCY_TYPE"].ToString());
                                this.drpDUTY_FREE_CURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DUTY_FREE_CURRENCY_TYPE"].ToString());

                                this.txtNOTE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["NOTE"].ToString());
                                this.txtQUOTATION_VALID_DATE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["QUOTATION_VALID_DATE"].ToString());
                                this.txtCLERK.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CLERK"].ToString());
                                this.txtCLERK_TEL.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CLERK_TEL"].ToString());

                                dbConnection dba2 = new dbConnection();
                                OracleConnection myConnection = dba2.getOracleClientConnection();
                                //Dim myCommand As New OracleCommand(strSQL, myConnection)
                                //Dim strSQL As String = String.Format("select serial_no,DESCRIPTION,image from B2B_MATERIAL_IMAGE_SEQUENCE where code='{0}'and status=1 order by serial_no ", strPkey)
                                string strSQL = "select serial_no,DESCRIPTION,image from B2B_MATERIAL_IMAGE_SEQUENCE where code=:code and status=1 order by serial_no ";
                                //P3512S0159-針對B2B網站SCA弱點掃描修正程式============
                                OracleCommand myCommand = new OracleCommand(strSQL, myConnection);
                                myCommand.Parameters.Add(":code", OracleType.VarChar).Value = strPkey;
                                //P3512S0159-針對B2B網站SCA弱點掃描修正程式============

                                OracleDataAdapter MyDA = new OracleDataAdapter(myCommand);
                                DataSet ds1 = new DataSet();
                                MyDA.Fill(ds1);
                                myConnection.Close();
                                myConnection.Dispose();
                                this.btnVIEW1.Disabled = true;
                                this.btnVIEW2.Disabled = true;
                                this.btnVIEW3.Disabled = true;
                                int i = 0;
                                string CODE;
                                string PATH;
                                for (i = 0; i <= ds1.Tables[0].Rows.Count - 1; i++)
                                {
                                    switch (i)
                                    {
                                        case 0:
                                            this.txtPIC_NO1.Text = Server.HtmlEncode(ds1.Tables[0].Rows[i]["serial_no"].ToString());
                                            this.txtDESCRIPTION1.Text = Server.HtmlEncode(ds1.Tables[0].Rows[i]["DESCRIPTION"].ToString());
                                            if (ds1.Tables[0].Rows[i]["image"].ToString() == "")
                                            {
                                                this.btnVIEW1.Disabled = true;
                                                // Me.hidIMAGE1.Value = False
                                            }
                                            else
                                            {
                                                this.btnVIEW1.Disabled = false;
                                                // Me.hidIMAGE1.Value = True
                                            }
                                            break;
                                        //Me.chkDEL1.Enabled = True
                                        //Me.txtDESCRIPTION1.EnableView = False
                                        //Me.txtDESCRIPTION1.Enabled = True
                                        case 1:
                                            this.txtPIC_NO2.Text = Server.HtmlEncode(ds1.Tables[0].Rows[i]["serial_no"].ToString());
                                            this.txtDESCRIPTION2.Text = Server.HtmlEncode(ds1.Tables[0].Rows[i]["DESCRIPTION"].ToString());
                                            if (ds1.Tables[0].Rows[i]["image"].ToString() == "")
                                            {
                                                this.btnVIEW2.Disabled = true;
                                            }
                                            else
                                            {
                                                this.btnVIEW2.Disabled = false;
                                            }
                                            break;
                                        //Me.chkDEL2.Enabled = True
                                        //Me.txtDESCRIPTION2.EnableView = False
                                        //Me.txtDESCRIPTION2.Enabled = True
                                        case 2:
                                            this.txtPIC_NO3.Text = Server.HtmlEncode(ds1.Tables[0].Rows[i]["serial_no"].ToString());
                                            this.txtDESCRIPTION3.Text = Server.HtmlEncode(ds1.Tables[0].Rows[i]["DESCRIPTION"].ToString());
                                            if (ds1.Tables[0].Rows[i]["image"].ToString() == "")
                                            {
                                                this.btnVIEW3.Disabled = true;
                                            }
                                            else
                                            {
                                                this.btnVIEW3.Disabled = false;
                                            }
                                            break;
                                        //Me.chkDEL3.Enabled = True
                                        //Me.txtDESCRIPTION3.EnableView = False
                                        //Me.txtDESCRIPTION3.Enabled = True
                                    }
                                }
                            }
                            else
                            {
                                showException("對不起! 此筆資料，已被刪除");
                            }

                        }
                        else if ((string)(Page.Request["action_type"].ToUpper()) == "COPY")
                        {
                            this.chkDEL1.Enabled = false;
                            this.chkDEL2.Enabled = false;
                            this.chkDEL3.Enabled = false;
                            // 複製模式
                            this.btnDel.Visible = false;
                            string strPkey = Page.Request["CODE"];


                            //至db 查詢正在修改的這一筆
                            //string SelectCommand = string.Format("select A.*,B.*,B.EXP_DATE as END_DATE from  B2B_MATERIAL A ,B2B_SUPPLY B where A.CODE=B.CODE(+) AND A.CODE= \'{0}\'", strPkey);
                            string SelectCommand = string.Format("SELECT A.*,B.*,B.EXP_DATE as END_DATE , C.PAYMENT_TERM_NO || '-' || C.DESCRIPTION AS PAYMENT_TERM_DESCRIPTION FROM  B2B_MATERIAL A ,B2B_SUPPLY B,BAS_PAYMENT_TERM C WHERE B.PAYMENT_TERM_NO = C.PAYMENT_TERM_NO AND A.CODE=B.CODE(+) AND A.CODE= :strPkey");

                            m_arrParam.Clear();
                            m_arrParam.Add(dba.GetOracleParam(":strPkey", strPkey));

                            DataBase DataBase = new DataBase();
                            DataSet ds = default(DataSet);
                            ds = DataBase.Query_CLASS(SelectCommand, "B2B_MATERIAL", m_arrParam);
                            //DataSet ds = dba.runExecuteQuery("B2B_MATERIAL", SelectCommand, m_arrParam);
                            int Row = 0;
                            if (!(ds == null) && ds.Tables["info"].Rows[0]["ReturnCode"] != "100" && ds.Tables["info"].Rows[0]["ReturnCode"] != "999")
                            {
                                Row = System.Convert.ToInt32(ds.Tables["B2B_MATERIAL"].Rows.Count - 1);
                                this.txtENGLISH_SHORTNAME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ENGLISH_SHORTNAME"].ToString());
                                this.txtENGLISH_FULLNAME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ENGLISH_FULLNAME"].ToString());
                                this.txtCHINESE_SHORTNAME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CHINESE_SHORTNAME"].ToString());
                                this.txtCHINESE_FULLNAME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CHINESE_FULLNAME"].ToString());

                                //Leo Add 20090729 增加五個欄位
                                this.txtPROD_INFO_CHINESE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PROD_INFO_CHINESE"].ToString());
                                this.txtPROD_INFO_ENGLISH.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PROD_INFO_ENGLISH"].ToString());
                                this.txtPROD_SPEC_CHINESE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PROD_SPEC_CHINESE"].ToString());
                                this.txtPROD_SPEC_ENGLISH.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PROD_SPEC_ENGLISH"].ToString());
                                getBRAND(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["BRAND_ID"].ToString()));
                                this.drpBRAND_ID.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["BRAND_ID"].ToString());

                                //Leo add end

                                this.txtMINNUM_QTY.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["MINNUM_QTY"].ToString());

                                this.rdoMATERIAL_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["MATERIAL_TYPE"].ToString());
                                this.hidTYPE.Value = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["MATERIAL_TYPE"].ToString());
                                getCLASS();
                                this.drpVENDOR_KIND.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CLASS"].ToString());
                                this.rdoCONSIGNED.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CONSIGNED"].ToString());
                                this.txtLEAD_TIME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["LEAD_TIME"].ToString());
                                this.txtEXP_DATELINE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["EXP_DATE"].ToString());
                                this.drpPACKAGE_UNIT.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PACKAGE_UNIT"].ToString());
                                this.txtSUPPLY_PRICE.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["SUPPLY_PRICE"].ToString()));
                                // Me.txtCURRENCY_TYPE.Text = LoginUser.CURRENCY_TYPE
                                this.txtCOEFFICIENT.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["COEFFICIENT"].ToString());
                                this.txtPACK_DETAIL.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PACK_DETAIL"].ToString());
                                this.txtDIMENSION_L.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DIMENSION_L"].ToString()));
                                this.txtDIMENSION_H.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DIMENSION_H"].ToString()));
                                this.txtDIMENSION_W.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DIMENSION_W"].ToString()));
                                this.txtGROSS_WEIGHT.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["GROSS_WEIGHT"].ToString()));
                                //Update S8970025

                                string DELIVERY_TERM = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[0]["DELIVERY_TERM"].ToString());
                                //20100901 JAFF ADD---------------
                                if (DELIVERY_TERM.IndexOf("_") != -1) //判斷是否有分格符號
                                {
                                    Array TERM = DELIVERY_TERM.Split('_');
                                    if (this.drpDELIVERY_TERM.Items.IndexOf(this.drpDELIVERY_TERM.Items.FindByValue(TERM.GetValue(0).ToString())) != -1) //判斷抓出的TERM是否有在下拉選單內
                                    {
                                        this.drpDELIVERY_TERM.SelectedIndex = this.drpDELIVERY_TERM.Items.IndexOf(this.drpDELIVERY_TERM.Items.FindByValue(TERM.GetValue(0).ToString()));
                                        this.txtSEAPORT.Text = TERM.GetValue(1).ToString();
                                    }
                                    else
                                    {
                                        this.drpDELIVERY_TERM.Items.Insert(0, new ListItem(TERM.GetValue(0).ToString(), "NULL"));
                                        this.txtSEAPORT.Text = TERM.GetValue(1).ToString();
                                    }
                                }
                                else
                                {
                                    this.drpDELIVERY_TERM.Items.Insert(0, "");
                                    this.txtSEAPORT.Text = DELIVERY_TERM; //若沒有分格符號就將整個值塞給這個欄位
                                }
                                //------------------------------------
                                //If DELIVERY_TERM.Length > 11 Then
                                //    If DELIVERY_TERM.Substring(0, 11) = "FOB_Seaport" Then

                                //        Me.txtSEAPORT.Text = DELIVERY_TERM.Substring(11, DELIVERY_TERM.Length - 11)
                                //        DELIVERY_TERM = "FOB_Seaport"
                                //    End If
                                //End If

                                //If Me.drpDELIVERY_TERM.Items.IndexOf(Me.drpDELIVERY_TERM.Items.FindByValue(DELIVERY_TERM)) <> -1 Then
                                //    Me.drpDELIVERY_TERM.SelectedIndex = Me.drpDELIVERY_TERM.Items.IndexOf(Me.drpDELIVERY_TERM.Items.FindByValue(DELIVERY_TERM))
                                //Else
                                //    Me.drpDELIVERY_TERM.Items.Insert(0, New ListItem(DELIVERY_TERM, "NULL"))
                                //End If
                                //; Me.drpDELIVERY_TERM.SelectedValue = DELIVERY_TERM
                                //Me.txtDELIVERY_TERM.Text = DELIVERY_TERM '20100901 JAFF REMARK
                                string PAYMENT_TERM_NO = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[0]["PAYMENT_TERM_NO"].ToString());
                                if (this.drpPAYMENT_TERM_NO.Items.IndexOf(this.drpPAYMENT_TERM_NO.Items.FindByValue(PAYMENT_TERM_NO)) != -1)
                                {
                                    this.drpPAYMENT_TERM_NO.SelectedIndex = this.drpPAYMENT_TERM_NO.Items.IndexOf(this.drpPAYMENT_TERM_NO.Items.FindByValue(PAYMENT_TERM_NO));
                                }
                                else
                                {
                                    string PAYMENT_TERM_DESCRIPTION = ds.Tables["B2B_MATERIAL"].Rows[0]["PAYMENT_TERM_DESCRIPTION"].ToString();
                                    this.drpPAYMENT_TERM_NO.Items.Insert(0, new ListItem(PAYMENT_TERM_DESCRIPTION, PAYMENT_TERM_NO));
                                }
                                this.txtADVISED_PRICE.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ADVISED_PRICE"].ToString()));
                                // JOE ADD P3108M0777
                                if (ds.Tables["B2B_MATERIAL"].Rows[Row]["ADVISED_PRICE"].GetType().ToString() != "System.DBNull")
                                {
                                    double d = Double.Parse(ds.Tables["B2B_MATERIAL"].Rows[0]["ADVISED_PRICE"].ToString());
                                    //this.txtADVISED_PRICE_T.Text = (Math.Round(d * 1.05)).ToString(); ;
                                    this.txtADVISED_PRICE_T.Text = (Math.Round(d * 1.05, 0, MidpointRounding.AwayFromZero)).ToString();
                                    this.drpADVISED_T_CURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ADVISED_CURRENCY_TYPE"].ToString());
                                }

                                this.txtAVERAGE_PRICE.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["AVERAGE_PRICE"].ToString()));
                                this.txtDUTY_FREE_PRICE.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DUTY_FREE_PRICE"].ToString()));
                                this.drpCURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CURRENCY_TYPE"].ToString());
                                this.drpADVISED_CURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ADVISED_CURRENCY_TYPE"].ToString());
                                this.drpAVERAGE_CURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["AVERAGE_CURRENCY_TYPE"].ToString());
                                this.drpDUTY_FREE_CURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DUTY_FREE_CURRENCY_TYPE"].ToString());


                                this.txtNOTE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["NOTE"].ToString());
                                this.txtQUOTATION_VALID_DATE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["QUOTATION_VALID_DATE"].ToString());
                                this.txtCLERK.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CLERK"].ToString());
                                this.txtCLERK_TEL.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CLERK_TEL"].ToString());

                                this.drpPAYMENT_TERM_NO.SelectedValue = PAYMENT_TERM_NO;

                                dbConnection dba3 = new dbConnection();
                                OracleConnection myConnection = dba3.getOracleClientConnection();


                                //Dim strSQL As String = String.Format("select serial_no,DESCRIPTION,image from B2B_MATERIAL_IMAGE_SEQUENCE where code='{0}'and status=1 order by serial_no ", strPkey)
                                string strSQL = "select serial_no,DESCRIPTION,image from B2B_MATERIAL_IMAGE_SEQUENCE where code=:code and status=1 order by serial_no ";
                                //P3512S0159-針對B2B網站SCA弱點掃描修正程式============
                                OracleCommand myCommand = new OracleCommand(strSQL, myConnection);
                                myCommand.Parameters.Add(":code", OracleType.VarChar).Value = strPkey;
                                //P3512S0159-針對B2B網站SCA弱點掃描修正程式============
                                OracleDataAdapter MyDA = new OracleDataAdapter(myCommand);

                                DataSet ds1 = new DataSet();
                                MyDA.Fill(ds1);
                                myConnection.Close();
                                myConnection.Dispose();
                                this.btnVIEW1.Disabled = true;
                                this.btnVIEW2.Disabled = true;
                                this.btnVIEW3.Disabled = true;
                                int i = 0;
                                string CODE;
                                string PATH;
                                for (i = 0; i <= ds1.Tables[0].Rows.Count - 1; i++)
                                {
                                    switch (i)
                                    {
                                        case 0:
                                            this.txtPIC_NO1.Text = Server.HtmlEncode(ds1.Tables[0].Rows[i]["serial_no"].ToString());
                                            this.txtDESCRIPTION1.Text = Server.HtmlEncode(ds1.Tables[0].Rows[i]["DESCRIPTION"].ToString());
                                            if (ds1.Tables[0].Rows[i]["image"].ToString() == "")
                                            {
                                                this.btnVIEW1.Disabled = true;
                                                // Me.hidIMAGE1.Value = False
                                            }
                                            else
                                            {
                                                this.btnVIEW1.Disabled = false;
                                                // Me.hidIMAGE1.Value = True
                                            }
                                            this.chkDEL1.Enabled = true;
                                            this.txtDESCRIPTION1.EnableView = false;
                                            this.txtDESCRIPTION1.Enabled = true;
                                            break;
                                        case 1:
                                            this.txtPIC_NO2.Text = Server.HtmlEncode(ds1.Tables[0].Rows[i]["serial_no"].ToString());
                                            this.txtDESCRIPTION2.Text = Server.HtmlEncode(ds1.Tables[0].Rows[i]["DESCRIPTION"].ToString());
                                            if (ds1.Tables[0].Rows[i]["image"].ToString() == "")
                                            {
                                                this.btnVIEW2.Disabled = true;
                                            }
                                            else
                                            {
                                                this.btnVIEW2.Disabled = false;
                                            }
                                            this.chkDEL2.Enabled = true;
                                            this.txtDESCRIPTION2.EnableView = false;
                                            this.txtDESCRIPTION2.Enabled = true;
                                            break;
                                        case 2:
                                            this.txtPIC_NO3.Text = Server.HtmlEncode(ds1.Tables[0].Rows[i]["serial_no"].ToString());
                                            this.txtDESCRIPTION3.Text = Server.HtmlEncode(ds1.Tables[0].Rows[i]["DESCRIPTION"].ToString());
                                            if (ds1.Tables[0].Rows[i]["image"].ToString() == "")
                                            {
                                                this.btnVIEW3.Disabled = true;
                                            }
                                            else
                                            {
                                                this.btnVIEW3.Disabled = false;
                                            }
                                            this.chkDEL3.Enabled = true;
                                            this.txtDESCRIPTION3.EnableView = false;
                                            this.txtDESCRIPTION3.Enabled = true;
                                            break;
                                    }
                                }



                            }
                            else
                            {
                                showException("對不起! 此筆資料，已被刪除");
                            }
                        }
                        else if ((string)(Page.Request["action_type"].ToUpper()) == "DEL")
                        {
                            this.chkDEL1.Enabled = false;
                            this.chkDEL2.Enabled = false;
                            this.chkDEL3.Enabled = false;
                            // 刪除模式
                            string strPkey = Page.Request["CODE"];

                            this.btnSave.Visible = false;
                            this.btnDel.Visible = true;
                            this.txtENGLISH_SHORTNAME.EnableView = true;
                            this.txtENGLISH_FULLNAME.EnableView = true;
                            this.txtCHINESE_SHORTNAME.EnableView = true;
                            this.txtCHINESE_FULLNAME.EnableView = true;
                            //Me.rdoBONDED.Enabled = False
                            this.rdoMATERIAL_TYPE.Enabled = false;
                            this.drpVENDOR_KIND.Enabled = false;
                            this.rdoCONSIGNED.Enabled = false;
                            this.txtLEAD_TIME.EnableView = true;
                            this.txtEXP_DATELINE.EnableView = true;
                            this.drpPACKAGE_UNIT.Enabled = false;
                            this.txtSUPPLY_PRICE.EnableView = true;
                            //   Me.txtCURRENCY_TYPE.EnableView = True
                            this.txtCOEFFICIENT.EnableView = true;
                            this.txtPACK_DETAIL.EnableView = true;
                            this.txtDIMENSION_L.EnableView = true;
                            this.txtDIMENSION_H.EnableView = true;
                            this.txtDIMENSION_W.EnableView = true;
                            this.txtGROSS_WEIGHT.EnableView = true;
                            this.txtPATH1.Disabled = true;
                            this.txtPATH2.Disabled = true;
                            this.txtPATH3.Disabled = true;
                            this.txtDESCRIPTION1.EnableView = true;
                            this.txtDESCRIPTION2.EnableView = true;
                            this.txtDESCRIPTION3.EnableView = true;
                            //Update S8970025
                            this.txtADVISED_PRICE.EnableView = true;
                            this.txtDUTY_FREE_PRICE.EnableView = true;
                            this.txtAVERAGE_PRICE.EnableView = true;
                            this.drpCURRENCY_TYPE.Enabled = false;
                            this.drpADVISED_CURRENCY_TYPE.Enabled = false;
                            this.drpAVERAGE_CURRENCY_TYPE.Enabled = false;
                            this.drpDUTY_FREE_CURRENCY_TYPE.Enabled = false;

                            this.txtMINNUM_QTY.EnableView = true;
                            this.txtNOTE.EnableView = true;
                            this.txtQUOTATION_VALID_DATE.EnableView = true;
                            this.txtCLERK.EnableView = true;
                            this.txtCLERK_TEL.EnableView = true;
                            this.drpPAYMENT_TERM_NO.Enabled = false;
                            this.drpDELIVERY_TERM.Enabled = false; //20100901 JAFF DISCARD MARK
                            this.txtSEAPORT.EnableView = false; //20100901 JAFF ADD
                            //Me.txtDELIVERY_TERM.Enabled = False '20100901 JAFF MARK
                            //至db 查詢正在修改的這一筆
                            // string SelectCommand = string.Format("select A.*,B.*,B.EXP_DATE as END_DATE from  B2B_MATERIAL A ,B2B_SUPPLY B where A.CODE=B.CODE(+) AND A.CODE= \'{0}\'", strPkey);
                            string SelectCommand = "SELECT A.*,B.*,B.EXP_DATE as END_DATE , C.PAYMENT_TERM_NO || '-' || C.DESCRIPTION AS PAYMENT_TERM_DESCRIPTION FROM  B2B_MATERIAL A ,B2B_SUPPLY B,BAS_PAYMENT_TERM C WHERE B.PAYMENT_TERM_NO = C.PAYMENT_TERM_NO AND A.CODE=B.CODE(+) AND A.CODE= :strPkey";
                            m_arrParam.Clear();
                            m_arrParam.Add(dba.GetOracleParam(":strPkey", strPkey));

                            DataBase DataBase = new DataBase();
                            DataSet ds = default(DataSet);
                            ds = DataBase.Query_CLASS(SelectCommand, "B2B_MATERIAL", m_arrParam);
                            //DataSet ds = dba.runExecuteQuery("B2B_MATERIAL", SelectCommand, m_arrParam);

                            int Row = 0;
                            if (!(ds == null) && ds.Tables["info"].Rows[0]["ReturnCode"] != "100" && ds.Tables["info"].Rows[0]["ReturnCode"] != "999")
                            {
                                Row = System.Convert.ToInt32(ds.Tables["B2B_MATERIAL"].Rows.Count - 1);
                                txtPURCHASE_NO.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PURCHASE_NO"].ToString());
                                txtCODE_SEQ.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CODE"].ToString());
                                this.txtENGLISH_SHORTNAME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ENGLISH_SHORTNAME"].ToString());
                                this.txtENGLISH_FULLNAME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ENGLISH_FULLNAME"].ToString());
                                this.txtCHINESE_SHORTNAME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CHINESE_SHORTNAME"].ToString());
                                this.txtCHINESE_FULLNAME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CHINESE_FULLNAME"].ToString());

                                //Leo Add 20090729 增加五個欄位
                                this.txtPROD_INFO_CHINESE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PROD_INFO_CHINESE"].ToString());
                                this.txtPROD_INFO_ENGLISH.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PROD_INFO_ENGLISH"].ToString());
                                this.txtPROD_SPEC_CHINESE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PROD_SPEC_CHINESE"].ToString());
                                this.txtPROD_SPEC_ENGLISH.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PROD_SPEC_ENGLISH"].ToString());
                                getBRAND(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["BRAND_ID"].ToString()));
                                this.drpBRAND_ID.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["BRAND_ID"].ToString());

                                //Leo add end


                                this.txtMINNUM_QTY.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["MINNUM_QTY"].ToString());

                                this.rdoMATERIAL_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["MATERIAL_TYPE"].ToString());
                                this.hidTYPE.Value = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["MATERIAL_TYPE"].ToString());
                                getCLASS();
                                this.drpVENDOR_KIND.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CLASS"].ToString());
                                this.rdoCONSIGNED.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CONSIGNED"].ToString());
                                this.txtLEAD_TIME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["LEAD_TIME"].ToString());
                                this.txtEXP_DATELINE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["EXP_DATE"].ToString());
                                this.drpPACKAGE_UNIT.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PACKAGE_UNIT"].ToString());
                                this.txtSUPPLY_PRICE.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["SUPPLY_PRICE"].ToString()));
                                //Me.txtCURRENCY_TYPE.Text = LoginUser.CURRENCY_TYPE
                                this.txtCOEFFICIENT.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["COEFFICIENT"].ToString());
                                this.txtPACK_DETAIL.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PACK_DETAIL"].ToString());
                                this.txtDIMENSION_L.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DIMENSION_L"].ToString()));
                                this.txtDIMENSION_H.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DIMENSION_H"].ToString()));
                                this.txtDIMENSION_W.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DIMENSION_W"].ToString()));
                                this.txtGROSS_WEIGHT.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["GROSS_WEIGHT"].ToString()));
                                //Update S8970025

                                string DELIVERY_TERM = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[0]["DELIVERY_TERM"].ToString());
                                //20100901 JAFF ADD---------------
                                if (DELIVERY_TERM.IndexOf("_") != -1) //判斷是否有分格符號
                                {
                                    Array TERM = DELIVERY_TERM.Split('_');
                                    if (this.drpDELIVERY_TERM.Items.IndexOf(this.drpDELIVERY_TERM.Items.FindByValue(TERM.GetValue(0).ToString())) != -1) //判斷抓出的TERM是否有在下拉選單內
                                    {
                                        this.drpDELIVERY_TERM.SelectedIndex = this.drpDELIVERY_TERM.Items.IndexOf(this.drpDELIVERY_TERM.Items.FindByValue(TERM.GetValue(0).ToString()));
                                        this.txtSEAPORT.Text = TERM.GetValue(1).ToString();
                                    }
                                    else
                                    {
                                        this.drpDELIVERY_TERM.Items.Insert(0, new ListItem(TERM.GetValue(0).ToString(), "NULL"));
                                        this.txtSEAPORT.Text = TERM.GetValue(1).ToString();
                                    }
                                }
                                else
                                {
                                    this.drpDELIVERY_TERM.Items.Insert(0, "");
                                    this.txtSEAPORT.Text = DELIVERY_TERM; //若沒有分格符號就將整個值塞給這個欄位
                                }
                                //------------------------------------
                                //If DELIVERY_TERM.Length > 11 Then
                                //    If DELIVERY_TERM.Substring(0, 11) = "FOB_Seaport" Then

                                //        Me.txtSEAPORT.Text = DELIVERY_TERM.Substring(11, DELIVERY_TERM.Length - 11)
                                //        DELIVERY_TERM = "FOB_Seaport"
                                //    End If
                                //End If

                                //If Me.drpDELIVERY_TERM.Items.IndexOf(Me.drpDELIVERY_TERM.Items.FindByValue(DELIVERY_TERM)) <> -1 Then
                                //    Me.drpDELIVERY_TERM.SelectedIndex = Me.drpDELIVERY_TERM.Items.IndexOf(Me.drpDELIVERY_TERM.Items.FindByValue(DELIVERY_TERM))
                                //Else
                                //    Me.drpDELIVERY_TERM.Items.Insert(0, New ListItem(DELIVERY_TERM, "NULL"))
                                //End If
                                //  Me.drpDELIVERY_TERM.SelectedValue = DELIVERY_TERM
                                //Me.txtDELIVERY_TERM.Text = DELIVERY_TERM '20100901 JAFF MARK
                                string PAYMENT_TERM_NO = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[0]["PAYMENT_TERM_NO"].ToString());
                                if (this.drpPAYMENT_TERM_NO.Items.IndexOf(this.drpPAYMENT_TERM_NO.Items.FindByValue(PAYMENT_TERM_NO)) != -1)
                                {
                                    this.drpPAYMENT_TERM_NO.SelectedIndex = this.drpPAYMENT_TERM_NO.Items.IndexOf(this.drpPAYMENT_TERM_NO.Items.FindByValue(PAYMENT_TERM_NO));
                                }
                                else
                                {
                                    string PAYMENT_TERM_DESCRIPTION = ds.Tables["B2B_MATERIAL"].Rows[0]["PAYMENT_TERM_DESCRIPTION"].ToString();
                                    this.drpPAYMENT_TERM_NO.Items.Insert(0, new ListItem(PAYMENT_TERM_DESCRIPTION, PAYMENT_TERM_NO));
                                }

                                this.drpPAYMENT_TERM_NO.SelectedValue = PAYMENT_TERM_NO;
                                this.txtADVISED_PRICE.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ADVISED_PRICE"].ToString()));
                                // JOE ADD P3108M0777
                                if (ds.Tables["B2B_MATERIAL"].Rows[Row]["ADVISED_PRICE"].GetType().ToString() != "System.DBNull")
                                {
                                    this.txtADVISED_PRICE_T.Text = (Math.Round(double.Parse(ds.Tables["B2B_MATERIAL"].Rows[0]["ADVISED_PRICE"].ToString()) * 1.05)).ToString();
                                    this.drpADVISED_T_CURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ADVISED_CURRENCY_TYPE"].ToString());
                                }


                                this.txtAVERAGE_PRICE.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["AVERAGE_PRICE"].ToString()));
                                this.txtDUTY_FREE_PRICE.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DUTY_FREE_PRICE"].ToString()));
                                this.drpCURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CURRENCY_TYPE"].ToString());
                                this.drpADVISED_CURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ADVISED_CURRENCY_TYPE"].ToString());
                                this.drpAVERAGE_CURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["AVERAGE_CURRENCY_TYPE"].ToString());
                                this.drpDUTY_FREE_CURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DUTY_FREE_CURRENCY_TYPE"].ToString());

                                this.txtNOTE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["NOTE"].ToString());
                                this.txtQUOTATION_VALID_DATE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["QUOTATION_VALID_DATE"].ToString());
                                this.txtCLERK.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CLERK"].ToString());
                                this.txtCLERK_TEL.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CLERK_TEL"].ToString());

                                dbConnection dba4 = new dbConnection();
                                OracleConnection myConnection = dba4.getOracleClientConnection();
                                // Dim strSQL As String = String.Format("select serial_no,DESCRIPTION,image from B2B_MATERIAL_IMAGE_SEQUENCE where code='{0}'and status=1 order by serial_no ", strPkey)
                                string strSQL = "select serial_no,DESCRIPTION,image from B2B_MATERIAL_IMAGE_SEQUENCE where code=:code and status=1 order by serial_no ";
                                //P3512S0159-針對B2B網站SCA弱點掃描修正程式============
                                OracleCommand myCommand = new OracleCommand(strSQL, myConnection);
                                myCommand.Parameters.Add(":code", OracleType.VarChar).Value = strPkey;
                                //P3512S0159-針對B2B網站SCA弱點掃描修正程式============
                                OracleDataAdapter MyDA = new OracleDataAdapter(myCommand);
                                DataSet ds1 = new DataSet();
                                MyDA.Fill(ds1);
                                myConnection.Close();
                                myConnection.Dispose();
                                this.btnVIEW1.Disabled = true;
                                this.btnVIEW2.Disabled = true;
                                this.btnVIEW3.Disabled = true;
                                int i = 0;
                                string CODE;
                                string PATH;
                                for (i = 0; i <= ds1.Tables[0].Rows.Count - 1; i++)
                                {
                                    switch (i)
                                    {
                                        case 0:
                                            this.txtPIC_NO1.Text = Server.HtmlEncode(ds1.Tables[0].Rows[i]["serial_no"].ToString());
                                            this.txtDESCRIPTION1.Text = Server.HtmlEncode(ds1.Tables[0].Rows[i]["DESCRIPTION"].ToString());
                                            if (ds1.Tables[0].Rows[i]["image"].ToString() == "")
                                            {
                                                this.btnVIEW1.Disabled = true;
                                                // Me.hidIMAGE1.Value = False
                                            }
                                            else
                                            {
                                                this.btnVIEW1.Disabled = false;
                                                // Me.hidIMAGE1.Value = True
                                            }
                                            break;
                                        //Me.chkDEL1.Enabled = True
                                        //Me.txtDESCRIPTION1.EnableView = False
                                        //Me.txtDESCRIPTION1.Enabled = True
                                        case 1:
                                            this.txtPIC_NO2.Text = Server.HtmlEncode(ds1.Tables[0].Rows[i]["serial_no"].ToString());
                                            this.txtDESCRIPTION2.Text = Server.HtmlEncode(ds1.Tables[0].Rows[i]["DESCRIPTION"].ToString());
                                            if (ds1.Tables[0].Rows[i]["image"].ToString() == "")
                                            {
                                                this.btnVIEW2.Disabled = true;
                                            }
                                            else
                                            {
                                                this.btnVIEW2.Disabled = false;
                                            }
                                            break;
                                        //Me.chkDEL2.Enabled = True
                                        //Me.txtDESCRIPTION2.EnableView = False
                                        //Me.txtDESCRIPTION2.Enabled = True
                                        case 2:
                                            this.txtPIC_NO3.Text = Server.HtmlEncode(ds1.Tables[0].Rows[i]["serial_no"].ToString());
                                            this.txtDESCRIPTION3.Text = Server.HtmlEncode(ds1.Tables[0].Rows[i]["DESCRIPTION"].ToString());
                                            if (ds1.Tables[0].Rows[i]["image"].ToString() == "")
                                            {
                                                this.btnVIEW3.Disabled = true;
                                            }
                                            else
                                            {
                                                this.btnVIEW3.Disabled = false;
                                            }
                                            break;
                                        //Me.chkDEL3.Enabled = True
                                        //Me.txtDESCRIPTION3.EnableView = False
                                        //Me.txtDESCRIPTION3.Enabled = True
                                    }
                                }
                            }
                            else
                            {
                                showException("對不起! 此筆資料，已被刪除");
                            }
                        }
                        else
                        {
                        }



                    }
                    else
                    {

                        this.hidTYPE.Value = this.rdoMATERIAL_TYPE.SelectedValue;
                        getCLASS();
                        string material_class = this.hidCLASS.Value;

                        if (this.drpVENDOR_KIND.Items.IndexOf(this.drpVENDOR_KIND.Items.FindByValue(material_class)) != -1)
                        {
                            this.drpVENDOR_KIND.SelectedIndex = this.drpVENDOR_KIND.Items.IndexOf(this.drpVENDOR_KIND.Items.FindByValue(material_class));
                        }
                        else
                        {
                            this.drpVENDOR_KIND.Items.Insert(0, new ListItem(material_class, ""));
                        }

                    }
                }
                else //Adams: action type = SMAS
                {
                    getDELIVERY_TERM();
                    getCLASS();
                    getCURRENCY_TYPE();
                    getBRAND("");
                    getPAYMENT_TERM(Page.Request["VENDOR_TYPE"]);
                    // SAMS查詢模式
                    this.chkDEL1.Enabled = false;
                    this.chkDEL2.Enabled = false;
                    this.chkDEL3.Enabled = false;
                    this.btnDel.Visible = false;
                    this.btnSave.Visible = true; //Adams:add in 2014/8/14
                    btnExit.Visible = false; //Adams:add in 2014/8/4
                    string strPkey = Page.Request["CODE"];
                    this.txtENGLISH_SHORTNAME.EnableView = true;
                    this.txtENGLISH_FULLNAME.EnableView = true;
                    this.txtCHINESE_SHORTNAME.EnableView = true;
                    this.txtCHINESE_FULLNAME.EnableView = true;
                    this.rdoMATERIAL_TYPE.Enabled = false;
                    this.drpVENDOR_KIND.Enabled = false;
                    this.rdoCONSIGNED.Enabled = false;
                    this.txtLEAD_TIME.EnableView = true;
                    this.txtEXP_DATELINE.EnableView = true;
                    this.drpPACKAGE_UNIT.Enabled = false;
                    this.txtSUPPLY_PRICE.EnableView = true;
                    this.txtCOEFFICIENT.EnableView = true;
                    this.txtPACK_DETAIL.EnableView = true;
                    this.txtDIMENSION_L.EnableView = true;
                    this.txtDIMENSION_H.EnableView = true;
                    this.txtDIMENSION_W.EnableView = true;
                    this.txtGROSS_WEIGHT.EnableView = true;

                    //Update S8970025
                    this.txtADVISED_PRICE.EnableView = true;
                    this.txtDUTY_FREE_PRICE.EnableView = true;
                    this.txtAVERAGE_PRICE.EnableView = true;
                    this.drpCURRENCY_TYPE.Enabled = false;
                    this.drpADVISED_CURRENCY_TYPE.Enabled = false;
                    this.drpAVERAGE_CURRENCY_TYPE.Enabled = false;
                    this.drpDUTY_FREE_CURRENCY_TYPE.Enabled = false;

                    this.txtMINNUM_QTY.EnableView = true;
                    this.txtNOTE.EnableView = true;
                    this.txtQUOTATION_VALID_DATE.EnableView = true;
                    this.txtCLERK.EnableView = true;
                    this.txtCLERK_TEL.EnableView = true;
                    this.drpPAYMENT_TERM_NO.Enabled = false;
                    this.drpDELIVERY_TERM.Enabled = false; //20100901 JAFF DISCARD MARK
                    this.txtSEAPORT.EnableView = false; //20100901 JAFF ADD
                    //Me.txtDELIVERY_TERM.Enabled = False  '20100901 JAFF MARK


                    //至db 查詢正在修改的這一筆
                    //string SelectCommand = string.Format("select A.*,B.*,B.EXP_DATE as END_DATE from  B2B_MATERIAL A ,B2B_SUPPLY B where A.CODE=B.CODE(+) AND A.CODE= \'{0}\'", strPkey);
                    string SelectCommand = "SELECT A.*,B.*,B.EXP_DATE as END_DATE , C.PAYMENT_TERM_NO || '-' || C.DESCRIPTION AS PAYMENT_TERM_DESCRIPTION FROM  B2B_MATERIAL A ,B2B_SUPPLY B,BAS_PAYMENT_TERM C WHERE B.PAYMENT_TERM_NO = C.PAYMENT_TERM_NO AND A.CODE=B.CODE(+) AND A.CODE= :strPkey";
                    m_arrParam.Clear();
                    m_arrParam.Add(dba.GetOracleParam(":strPkey", strPkey));

                    DataBase DataBase = new DataBase();
                    DataSet ds = default(DataSet);
                    ds = DataBase.Query_CLASS(SelectCommand, "B2B_MATERIAL", m_arrParam);

                    //DataSet ds = dba.runExecuteQuery("B2B_MATERIAL", SelectCommand, m_arrParam);
                    int Row = 0;
                    if (!(ds == null) && ds.Tables["info"].Rows[0]["ReturnCode"] != "100" && ds.Tables["info"].Rows[0]["ReturnCode"] != "999")
                    {
                        Row = System.Convert.ToInt32(ds.Tables["B2B_MATERIAL"].Rows.Count - 1);
                        txtCODE_SEQ.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CODE"].ToString());
                        txtPURCHASE_NO.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PURCHASE_NO"].ToString());
                        this.txtENGLISH_SHORTNAME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ENGLISH_SHORTNAME"].ToString());
                        this.txtENGLISH_FULLNAME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ENGLISH_FULLNAME"].ToString());
                        this.txtCHINESE_SHORTNAME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CHINESE_SHORTNAME"].ToString());
                        this.txtCHINESE_FULLNAME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CHINESE_FULLNAME"].ToString());

                        //Leo Add 20090729 增加五個欄位
                        this.txtPROD_INFO_CHINESE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PROD_INFO_CHINESE"].ToString());
                        this.txtPROD_INFO_ENGLISH.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PROD_INFO_ENGLISH"].ToString());
                        this.txtPROD_SPEC_CHINESE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PROD_SPEC_CHINESE"].ToString());
                        this.txtPROD_SPEC_ENGLISH.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PROD_SPEC_ENGLISH"].ToString());

                        this.drpBRAND_ID.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["BRAND_ID"].ToString());

                        //Leo add end
                        this.txtMINNUM_QTY.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["MINNUM_QTY"].ToString());

                        this.rdoMATERIAL_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["MATERIAL_TYPE"].ToString());
                        this.hidTYPE.Value = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["MATERIAL_TYPE"].ToString());
                        getCLASS();
                        this.drpVENDOR_KIND.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CLASS"].ToString());
                        this.rdoCONSIGNED.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CONSIGNED"].ToString());
                        this.txtLEAD_TIME.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["LEAD_TIME"].ToString());
                        this.txtEXP_DATELINE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["EXP_DATE"].ToString());
                        this.drpPACKAGE_UNIT.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PACKAGE_UNIT"].ToString());
                        this.txtSUPPLY_PRICE.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["SUPPLY_PRICE"].ToString()));
                        this.txtCOEFFICIENT.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["COEFFICIENT"].ToString());
                        this.txtPACK_DETAIL.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PACK_DETAIL"].ToString());
                        this.txtDIMENSION_L.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DIMENSION_L"].ToString()));
                        this.txtDIMENSION_H.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DIMENSION_H"].ToString()));
                        this.txtDIMENSION_W.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DIMENSION_W"].ToString()));
                        this.txtGROSS_WEIGHT.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["GROSS_WEIGHT"].ToString()));
                        //Update S8970025

                        string DELIVERY_TERM = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[0]["DELIVERY_TERM"].ToString());
                        //20100901 JAFF ADD---------------
                        if (DELIVERY_TERM.IndexOf("_") != -1) //判斷是否有分格符號
                        {
                            Array TERM = DELIVERY_TERM.Split('_');
                            if (this.drpDELIVERY_TERM.Items.IndexOf(this.drpDELIVERY_TERM.Items.FindByValue(TERM.GetValue(0).ToString())) != -1) //判斷抓出的TERM是否有在下拉選單內
                            {
                                this.drpDELIVERY_TERM.SelectedIndex = this.drpDELIVERY_TERM.Items.IndexOf(this.drpDELIVERY_TERM.Items.FindByValue(TERM.GetValue(0).ToString()));
                                this.txtSEAPORT.Text = TERM.GetValue(1).ToString();
                            }
                            else
                            {
                                this.drpDELIVERY_TERM.Items.Insert(0, new ListItem(TERM.GetValue(0).ToString(), "NULL"));
                                this.txtSEAPORT.Text = TERM.GetValue(1).ToString();
                            }
                        }
                        else
                        {
                            this.drpDELIVERY_TERM.Items.Insert(0, "");
                            this.txtSEAPORT.Text = DELIVERY_TERM; //若沒有分格符號就將整個值塞給這個欄位
                        }
                        //If DELIVERY_TERM.Length > 11 Then
                        //    If DELIVERY_TERM.Substring(0, 11) = "FOB_Seaport" Then

                        //        Me.txtSEAPORT.Text = DELIVERY_TERM.Substring(11, DELIVERY_TERM.Length - 11)
                        //        DELIVERY_TERM = "FOB_Seaport"
                        //    End If
                        //End If

                        //If Me.drpDELIVERY_TERM.Items.IndexOf(Me.drpDELIVERY_TERM.Items.FindByValue(DELIVERY_TERM)) <> -1 Then
                        //    Me.drpDELIVERY_TERM.SelectedIndex = Me.drpDELIVERY_TERM.Items.IndexOf(Me.drpDELIVERY_TERM.Items.FindByValue(DELIVERY_TERM))
                        //Else
                        //    Me.drpDELIVERY_TERM.Items.Insert(0, New ListItem(DELIVERY_TERM, "NULL"))
                        //End If
                        //  Me.drpDELIVERY_TERM.SelectedValue = ds.Tables("B2B_MATERIAL").Rows(Row)("DELIVERY_TERM").ToString()
                        //txtDELIVERY_TERM.Text = ds.Tables("B2B_MATERIAL").Rows(Row)("DELIVERY_TERM").ToString() 20100901 JAFF MARK
                        string PAYMENT_TERM_NO = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[0]["PAYMENT_TERM_NO"].ToString());
                        if (this.drpPAYMENT_TERM_NO.Items.IndexOf(this.drpPAYMENT_TERM_NO.Items.FindByValue(PAYMENT_TERM_NO)) != -1)
                        {
                            this.drpPAYMENT_TERM_NO.SelectedIndex = this.drpPAYMENT_TERM_NO.Items.IndexOf(this.drpPAYMENT_TERM_NO.Items.FindByValue(PAYMENT_TERM_NO));
                        }
                        else
                        {
                            string PAYMENT_TERM_DESCRIPTION = ds.Tables["B2B_MATERIAL"].Rows[0]["PAYMENT_TERM_DESCRIPTION"].ToString();
                            this.drpPAYMENT_TERM_NO.Items.Insert(0, new ListItem(PAYMENT_TERM_DESCRIPTION, PAYMENT_TERM_NO));
                        }

                        this.drpPAYMENT_TERM_NO.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["PAYMENT_TERM_NO"].ToString());
                        this.txtADVISED_PRICE.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ADVISED_PRICE"].ToString()));

                        //Me.drpADVISED_T_CURRENCY_TYPE.SelectedValue = ds.Tables("B2B_MATERIAL").Rows(Row)("ADVISED_CURRENCY_TYPE").ToString() ' JOE ADD 777
                        // JOE ADD P3108M0777
                        if (ds.Tables["B2B_MATERIAL"].Rows[Row]["ADVISED_PRICE"].GetType().ToString() != "System.DBNull")
                        {
                            this.txtADVISED_PRICE_T.Text = System.Convert.ToString(Math.Round(double.Parse(ds.Tables["B2B_MATERIAL"].Rows[Row]["ADVISED_PRICE"].ToString()) * 1.05));
                            this.drpADVISED_T_CURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ADVISED_CURRENCY_TYPE"].ToString());
                        }


                        this.txtAVERAGE_PRICE.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["AVERAGE_PRICE"].ToString()));
                        this.txtDUTY_FREE_PRICE.Text = StringFormat(System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DUTY_FREE_PRICE"].ToString()));
                        this.drpCURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CURRENCY_TYPE"].ToString());
                        this.drpADVISED_CURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["ADVISED_CURRENCY_TYPE"].ToString());
                        this.drpAVERAGE_CURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["AVERAGE_CURRENCY_TYPE"].ToString());
                        this.drpDUTY_FREE_CURRENCY_TYPE.SelectedValue = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["DUTY_FREE_CURRENCY_TYPE"].ToString());

                        this.txtNOTE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["NOTE"].ToString());
                        this.txtQUOTATION_VALID_DATE.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["QUOTATION_VALID_DATE"].ToString());
                        this.txtCLERK.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CLERK"].ToString());
                        this.txtCLERK_TEL.Text = System.Convert.ToString(ds.Tables["B2B_MATERIAL"].Rows[Row]["CLERK_TEL"].ToString());

                        dbConnection dba5 = new dbConnection();
                        OracleConnection myConnection = dba5.getOracleClientConnection();
                        //Dim strSQL As String = String.Format("select serial_no,DESCRIPTION,image from B2B_MATERIAL_IMAGE_SEQUENCE where code='{0}'and status=1 order by serial_no ", strPkey)
                        string strSQL = "select serial_no,DESCRIPTION,image from B2B_MATERIAL_IMAGE_SEQUENCE where code=:code and status=1 order by serial_no ";
                        //P3512S0159-針對B2B網站SCA弱點掃描修正程式============
                        OracleCommand myCommand = new OracleCommand(strSQL, myConnection);
                        myCommand.Parameters.Add(":code", OracleType.VarChar).Value = strPkey;
                        //P3512S0159-針對B2B網站SCA弱點掃描修正程式============
                        OracleDataAdapter MyDA = new OracleDataAdapter(myCommand);
                        DataSet ds1 = new DataSet();
                        MyDA.Fill(ds1);
                        myConnection.Close();
                        myConnection.Dispose();
                        this.btnVIEW1.Disabled = true;
                        this.btnVIEW2.Disabled = true;
                        this.btnVIEW3.Disabled = true;
                        int i = 0;
                        string CODE;
                        string PATH;
                        for (i = 0; i <= ds1.Tables[0].Rows.Count - 1; i++)
                        {
                            switch (i)
                            {
                                case 0:
                                    this.txtPIC_NO1.Text = Server.HtmlEncode(ds1.Tables[0].Rows[i]["serial_no"].ToString());

                                    //string SelectCommand_d_1 = string.Format("select DESCRIPTION from B2B_MATERIAL_IMAGE_SEQUENCE where code=\'{0}\'and status=1 and serial_no=\'{1}\'  ", strPkey, ds1.Tables[0].Rows[i]["serial_no"].ToString());
                                    string SelectCommand_d_1 = "select DESCRIPTION from B2B_MATERIAL_IMAGE_SEQUENCE where code=:strPkey and status=1 and serial_no=:serialNO  ";
                                    m_arrParam.Clear();
                                    m_arrParam.Add(dba.GetOracleParam(":strPkey", strPkey));
                                    m_arrParam.Add(dba.GetOracleParam(":serialNO", ds1.Tables[0].Rows[i]["serial_no"].ToString()));
                                    // DataSet dsd_1 = dba.runExecuteQuery("B2B_MATERIAL_IMAGE_SEQUENCE", SelectCommand_d_1, m_arrParam);
                                    DataSet dsd_1 = default(DataSet);
                                    dsd_1 = DataBase.Query_CLASS(SelectCommand_d_1, "B2B_MATERIAL_IMAGE_SEQUENCE", m_arrParam);

                                    int Rowd_1;
                                    if (!(dsd_1 == null) && dsd_1.Tables["info"].Rows[0]["ReturnCode"] != "100" && dsd_1.Tables["info"].Rows[0]["ReturnCode"] != "999")
                                    {
                                        this.txtDESCRIPTION1.Text = System.Convert.ToString(dsd_1.Tables["B2B_MATERIAL_IMAGE_SEQUENCE"].Rows[Row]["DESCRIPTION"].ToString());
                                    }
                                    // Me.txtDESCRIPTION1.Text = ds1.Tables(0).Rows(i)("DESCRIPTION").ToString()
                                    if (ds1.Tables[0].Rows[i]["image"].ToString() == "")
                                    {
                                        this.btnVIEW1.Disabled = true;
                                        // Me.hidIMAGE1.Value = False
                                    }
                                    else
                                    {
                                        this.btnVIEW1.Disabled = false;
                                        // Me.hidIMAGE1.Value = True
                                    }
                                    this.chkDEL1.Enabled = true;
                                    this.txtDESCRIPTION1.EnableView = false;
                                    this.txtDESCRIPTION1.Enabled = true;
                                    break;
                                case 1:
                                    this.txtPIC_NO2.Text = Server.HtmlEncode(ds1.Tables[0].Rows[i]["serial_no"].ToString());
                                    //string SelectCommand_d_2 = string.Format("select DESCRIPTION from B2B_MATERIAL_IMAGE_SEQUENCE where code=\'{0}\'and status=1 and serial_no=\'{1}\'  ", strPkey, ds1.Tables[0].Rows[i]["serial_no"].ToString());
                                    string SelectCommand_d_2 = "select DESCRIPTION from B2B_MATERIAL_IMAGE_SEQUENCE where code=:strPkey and status=1 and serial_no=:serialNO  ";
                                    DataSet dsd_2 = default(DataSet);
                                    m_arrParam.Clear();
                                    m_arrParam.Add(dba.GetOracleParam(":strPkey", strPkey));
                                    m_arrParam.Add(dba.GetOracleParam(":serialNO", ds1.Tables[0].Rows[i]["serial_no"].ToString()));
                                    dsd_2 = DataBase.Query_CLASS(SelectCommand_d_2, "B2B_MATERIAL_IMAGE_SEQUENCE", m_arrParam);
                                    //DataSet dsd_2 = new DataBase().Query_CLASS(SelectCommand_d_2, "B2B_MATERIAL_IMAGE_SEQUENCE", m_arrParam);
                                    int Rowd_2;
                                    if (!(dsd_2 == null) && dsd_2.Tables["info"].Rows[0]["ReturnCode"] != "100" && dsd_2.Tables["info"].Rows[0]["ReturnCode"] != "999")
                                    {
                                        this.txtDESCRIPTION2.Text = System.Convert.ToString(dsd_2.Tables["B2B_MATERIAL_IMAGE_SEQUENCE"].Rows[Row]["DESCRIPTION"].ToString());
                                    }

                                    if (ds1.Tables[0].Rows[i]["image"].ToString() == "")
                                    {
                                        this.btnVIEW2.Disabled = true;
                                    }
                                    else
                                    {
                                        this.btnVIEW2.Disabled = false;
                                    }
                                    this.chkDEL2.Enabled = true;
                                    this.txtDESCRIPTION2.EnableView = false;
                                    this.txtDESCRIPTION2.Enabled = true;
                                    break;
                                case 2:
                                    this.txtPIC_NO3.Text = Server.HtmlEncode(ds1.Tables[0].Rows[i]["serial_no"].ToString());
                                    //string SelectCommand_d = string.Format("select DESCRIPTION from B2B_MATERIAL_IMAGE_SEQUENCE where code=\'{0}\'and status=1 and serial_no=\'{1}\'  ", strPkey, ds1.Tables[0].Rows[i]["serial_no"].ToString());
                                    string SelectCommand_d = "select DESCRIPTION from B2B_MATERIAL_IMAGE_SEQUENCE where code=:strPkey and status=1 and serial_no=:serialNO  ";
                                    //DataSet dsd = default(DataSet);
                                    //dsd = DataBase.Query_CLASS(SelectCommand_d, "B2B_MATERIAL_IMAGE_SEQUENCE");
                                    m_arrParam.Clear();
                                    m_arrParam.Add(dba.GetOracleParam(":strPkey", strPkey));
                                    m_arrParam.Add(dba.GetOracleParam(":serialNO", ds1.Tables[0].Rows[i]["serial_no"].ToString()));
                                    DataSet dsd = DataBase.Query_CLASS(SelectCommand_d, "B2B_MATERIAL_IMAGE_SEQUENCE", m_arrParam);
                                    int Rowd;
                                    if (!(dsd == null) && dsd.Tables["info"].Rows[0]["ReturnCode"] != "100" && dsd.Tables["info"].Rows[0]["ReturnCode"] != "999")
                                    {
                                        this.txtDESCRIPTION3.Text = System.Convert.ToString(dsd.Tables["B2B_MATERIAL_IMAGE_SEQUENCE"].Rows[Row]["DESCRIPTION"].ToString());
                                    }
                                    if (ds1.Tables[0].Rows[i]["image"].ToString() == "")
                                    {
                                        this.btnVIEW3.Disabled = true;
                                    }
                                    else
                                    {
                                        this.btnVIEW3.Disabled = false;
                                    }
                                    this.chkDEL3.Enabled = true;
                                    this.txtDESCRIPTION3.EnableView = false;
                                    this.txtDESCRIPTION3.Enabled = true;
                                    break;
                            }
                        }
                    }
                    else
                    {
                        showException("對不起! 此筆資料，已被刪除");
                    }

                }



            }
            catch (Exception ex)
            {
                showException(ex.Message);
            }
        }

        private void btnSAVE_Click(System.Object sender, System.EventArgs e)
        {
            // 判斷交易動作
            try
            {
                string strErrorMessage = string.Empty;
                for (int i = 1; i <= 3; i++)
                {
                    HtmlInputFile txtPath = (HtmlInputFile)(FindControl("txtPath" + i.ToString()));
                    string strMessage = string.Empty;

                    if (!(txtPath == null) && txtPath.Value != string.Empty &&
                        !checkImageInfo(txtPath.PostedFile.InputStream, ref strMessage))
                    {

                        string strFileName = txtPath.PostedFile.FileName;
                        strErrorMessage += strFileName.Substring(strFileName.LastIndexOf("\\") + 1) + ": " + strMessage + "\\n";
                    }
                }

                if (strErrorMessage != string.Empty)
                {
                    this.RegisterStartupScript(Guid.NewGuid().ToString(), "<script type=\'text/javascript\'>alert(\'" + strErrorMessage + "\');</script>");
                    return;
                }

                string action_type = this.Request["action_type"].ToString();
                if (action_type == "ADD" || action_type == "COPY" || action_type == "BULLETIN")
                {
                    addMATERIAL(this.Request["action_type"].ToString());
                }
                else
                {
                    updMATERIAL(this.Request["action_type"].ToString());
                }
            }
            catch (Exception ex)
            {
                showException(ex.Message);
            }

        }

        private void btnDEL_Click(System.Object sender, System.EventArgs e)
        {
            delMATERIAL(null);
        }

        //check image infomation
        private bool checkImageInfo(Stream imgStream, ref string strCheckMessage)
        {
            int nLimitSize = 1024 * int.Parse(System.Configuration.ConfigurationManager.AppSettings["FileSize"]);
            bool bReturn = true;
            System.Drawing.Image img = default(System.Drawing.Image);

            try
            {

                img = System.Drawing.Image.FromStream(imgStream);
                ImageFormat imgFormat = img.RawFormat;
                ResourceManager rm = new ResourceManager(System.Convert.ToString("smasb2b." + System.Convert.ToString(Session["langauage"])), System.Reflection.Assembly.GetExecutingAssembly());

                if (imgFormat.Equals(ImageFormat.Jpeg))
                {
                    if (drpVENDOR_KIND.SelectedValue == "G")
                    {
                        if (img.Size.Width > 800 && img.Size.Height > 800)
                        {
                            strCheckMessage = rm.GetString("MSG070");

                            bReturn = false;
                            //Modfy By EmilyLi On 20100708 - 物品開發課阿偉告之取消此限制
                            //ElseIf Math.Abs(img.Size.Width - img.Size.Height) > 50 Then
                            // strCheckMessage = rm.GetString("MSG071")

                            //bReturn = False
                        }

                    }
                    else if (imgStream.Length > 600 * 1024)
                    {
                        strCheckMessage = rm.GetString("MSG072");

                        bReturn = false;
                    }
                    //By stan 架構提升案 20140721 符合800*800
                    else if (img.Size.Width > 800 && img.Size.Height > 800)
                    {
                        strCheckMessage = rm.GetString("MSG055");

                        bReturn = false;
                    }
                    else if (imgStream.Length > nLimitSize)
                    {
                        strCheckMessage = rm.GetString("MSG054");

                        bReturn = false;
                    }
                }
                else if (imgFormat.Equals(ImageFormat.Gif))
                {
                    if (imgStream.Length > nLimitSize)
                    {
                        strCheckMessage = rm.GetString("MSG054");

                        bReturn = false;
                    }
                }
                else
                {
                    strCheckMessage = "Unknown image format";

                    bReturn = false;
                }

            }
            catch (Exception ex)
            {
                strCheckMessage = ex.Message;
                bReturn = false;
            }
            finally
            {
                if (!(img == null))
                {
                    img.Dispose();
                }
                imgStream.Seek(0, SeekOrigin.Begin);
            }

            return bReturn;
        }
        //insert sub
        private void addMATERIAL(string type)
        {
            // 設定傳送的 DataSet 物件


            com.ddsc.common.ddscDataSet ddscDs = new com.ddsc.common.ddscDataSet();
            DataSet ds = default(DataSet);
            VENDOR LoginUser = GetLoginUser();

            string[] SERIAL_ARRAY = new string[3];
            ArrayList IMAGE_ARRAY = new ArrayList(2);
            byte[] temp = new byte[1];
            IMAGE_ARRAY.Insert(0, temp);
            IMAGE_ARRAY.Insert(1, temp);
            IMAGE_ARRAY.Insert(2, temp);
            // 宣告回傳DataSet
            DataSet dsResult = new DataSet();
            try
            {
                //基本資料
                string code = "";
                DataBase DataBase = new DataBase();
                code = System.Convert.ToString(DataBase.GetDefaultTransactionNo("B2B"));
                this.txtCODE_SEQ.Text = code;
                com.ddsc.common.ddscDataTable ddscD = ddscDs.createDataTable("B2B_MATERIAL");
                // 新增Row至ddscD
                ddscD.addNewRow();
                // 設定dscDt各欄位Value，參數一：columnName,參數二：columnValue
                ddscD.setColumnValue("action", "string", "add");
                ddscD.setColumnValue("CODE", "string", code);
                ddscD.setColumnValue("PURCHASE_NO", "string", txtPURCHASE_NO.Text.Trim());

                //P3109M0050 修改B2B新品資料可KEY IN ' 導致後續修改錯誤之問題  BY Joe
                ddscD.setColumnValue("ENGLISH_SHORTNAME", "string", System.Convert.ToString(txtENGLISH_SHORTNAME.Text.Trim().Replace("\'", " ")));
                ddscD.setColumnValue("ENGLISH_FULLNAME", "string", System.Convert.ToString(txtENGLISH_FULLNAME.Text.Trim().Replace("\'", " ")));
                ddscD.setColumnValue("CHINESE_SHORTNAME", "string", System.Convert.ToString(this.txtCHINESE_SHORTNAME.Text.Trim().Replace("\'", " ")));
                ddscD.setColumnValue("CHINESE_FULLNAME", "string", System.Convert.ToString(this.txtCHINESE_FULLNAME.Text.Trim().Replace("\'", " ")));

                //P3109m0050

                ddscD.setColumnValue("MATERIAL_TYPE", "string", rdoMATERIAL_TYPE.SelectedValue);
                ddscD.setColumnValue("CLASS", "string", this.drpVENDOR_KIND.SelectedValue);
                ddscD.setColumnValue("CONSIGNED", "string", rdoCONSIGNED.SelectedValue);
                ddscD.setColumnValue("LEAD_TIME", "string", this.txtLEAD_TIME.Text.Trim());
                ddscD.setColumnValue("EXP_DATE", "string", this.txtEXP_DATELINE.Text.Trim());
                ddscD.setColumnValue("PACKAGE_UNIT", "string", drpPACKAGE_UNIT.SelectedValue.Trim());
                ddscD.setColumnValue("STORE_UNIT", "string", this.drpPACKAGE_UNIT.SelectedValue.Trim());
                ddscD.setColumnValue("COEFFICIENT", "string", this.txtCOEFFICIENT.Text.Trim());
                ddscD.setColumnValue("PACK_DETAIL", "string", this.txtPACK_DETAIL.Text.Trim());
                ddscD.setColumnValue("DIMENSION_L", "string", this.txtDIMENSION_L.Text.Trim());
                ddscD.setColumnValue("DIMENSION_W", "string", this.txtDIMENSION_W.Text.Trim());
                ddscD.setColumnValue("DIMENSION_H", "string", this.txtDIMENSION_H.Text.Trim());
                ddscD.setColumnValue("GROSS_WEIGHT", "string", this.txtGROSS_WEIGHT.Text.Trim());
                ddscD.setColumnValue("VENDOR_NO", "string", LoginUser.VENDOR_NO);
                //Update S8970025
                ddscD.setColumnValue("ORIGINAL_CODE", "string", code);

                ddscD.setColumnValue("BONDED", "string", "N");
                ddscD.setColumnValue("NOTE", "string", this.txtNOTE.Text.Trim());
                ddscD.setColumnValue("status", "string", "1");
                ddscD.setColumnValue("upd_id", "string", LoginUser.VENDOR_NO);
                ddscD.setColumnValue("upd_date", "string", SystemDate);
                ddscD.setColumnValue("upd_time", "string", SystemTime);
                ddscD.setColumnValue("crt_id", "string", LoginUser.VENDOR_NO);
                ddscD.setColumnValue("crt_date", "string", SystemDate);
                ddscD.setColumnValue("crt_time", "string", SystemTime);
                com.ddsc.common.ddscDataTable ddscDt = ddscDs.createDataTable("B2B_MATERIAL_IMAGE_SEQUENCE");
                int _num = 0;
                string serial = System.Convert.ToString(0);
                if (txtPIC_NO1.Text.Trim() != "")
                {
                    serial = txtPIC_NO1.Text.Trim();
                }
                else
                {
                    ds = Query_Serial(txtCODE_SEQ.Text);
                    if (!(ds == null) && ds.Tables["info"].Rows[0]["ReturnCode"] != "100" && ds.Tables["info"].Rows[0]["ReturnCode"] != "999")
                    {
                        if (!(ds.Tables["B2B_MATERIAL_IMAGE_SEQUENCE"] == null))
                        {
                            serial = ds.Tables["B2B_MATERIAL_IMAGE_SEQUENCE"].Rows[0]["serial_no"].ToString();
                            _num = getSerialNum(serial);
                            if (_num > 9)
                            {
                                serial = txtCODE_SEQ.Text.Trim() + "_" + _num;
                            }
                            else
                            {
                                serial = txtCODE_SEQ.Text.Trim() + "_" + "0" + _num;
                            }
                        }
                        else
                        {
                            _num = getSerialNum(serial);
                            serial = txtCODE_SEQ.Text.Trim() + "_" + "0" + _num;
                        }

                    }
                    else
                    {
                        serial = txtCODE_SEQ.Text.Trim() + "_" + "01";
                    }
                }
                if ((this.txtPATH1.Value != "" && this.chkDEL1.Checked == false) || this.txtDESCRIPTION1.Text != "")
                {
                    int bufSize = (int)this.txtPATH1.PostedFile.InputStream.Length;
                    byte[] ImageData = new byte[bufSize + 1];
                    int bytesRead = this.txtPATH1.PostedFile.InputStream.Read(ImageData, 0, bufSize);
                    string strSQL;

                    ddscDt.addNewRow();
                    // 設定dscDt各欄位Value，參數一：columnName,參數二：columnValue
                    if (txtPIC_NO1.Text.Trim() == "")
                    {
                        ddscDt.setColumnValue("action", "string", "add");
                        ddscDt.setColumnValue("crt_id", "string", LoginUser.VENDOR_NO);
                        ddscDt.setColumnValue("crt_date", "string", SystemDate);
                        ddscDt.setColumnValue("crt_time", "string", SystemTime);
                    }
                    else
                    {
                        ddscDt.setColumnValue("action", "string", "upd");
                        ddscDt.setWhereValue("CODE", txtCODE_SEQ.Text.Trim());
                        ddscDt.setWhereValue("SERIAL_NO", serial);

                    }
                    ddscDt.setColumnValue("CODE", "string", txtCODE_SEQ.Text.Trim());
                    ddscDt.setColumnValue("SERIAL_NO", "string", serial);
                    ddscDt.setColumnValue("DESCRIPTION", "string", this.txtDESCRIPTION1.Text);
                    ddscDt.setColumnValue("status", "string", "1");
                    ddscDt.setColumnValue("upd_id", "string", LoginUser.VENDOR_NO);
                    ddscDt.setColumnValue("upd_date", "string", SystemDate);
                    ddscDt.setColumnValue("upd_time", "string", SystemTime);
                    SERIAL_ARRAY[0] = serial;
                    IMAGE_ARRAY[0] = ImageData;
                }
                _num = 0;
                if (txtPIC_NO2.Text.Trim() != "")
                {
                    serial = txtPIC_NO2.Text.Trim();
                }
                else
                {
                    ds = Query_Serial(txtCODE_SEQ.Text);
                    if (!(ds == null) && ds.Tables["info"].Rows[0]["ReturnCode"] != "100" && ds.Tables["info"].Rows[0]["ReturnCode"] != "999")
                    {
                        if (!(ds.Tables["B2B_MATERIAL_IMAGE_SEQUENCE"] == null))
                        {
                            serial = ds.Tables["B2B_MATERIAL_IMAGE_SEQUENCE"].Rows[0]["serial_no"].ToString();
                            _num = this.getSerialNum(serial);
                            if (_num > 9)
                            {
                                serial = txtCODE_SEQ.Text.Trim() + "_" + _num;
                            }
                            else
                            {
                                serial = txtCODE_SEQ.Text.Trim() + "_" + "0" + _num;
                            }
                        }
                        else
                        {
                            _num = this.getSerialNum(serial);
                            serial = txtCODE_SEQ.Text.Trim() + "_" + "0" + _num;
                        }

                    }
                    else
                    {
                        serial = txtCODE_SEQ.Text.Trim() + "_" + "01";
                    }
                }
                if ((this.txtPATH2.Value != "" && this.chkDEL2.Checked == false) || this.txtDESCRIPTION2.Text != "")
                {
                    int bufSize = (int)this.txtPATH2.PostedFile.InputStream.Length;
                    byte[] ImageData = new byte[bufSize + 1];
                    int bytesRead = this.txtPATH2.PostedFile.InputStream.Read(ImageData, 0, bufSize);
                    string strSQL;

                    ddscDt.addNewRow();
                    // 設定dscDt各欄位Value，參數一：columnName,參數二：columnValue
                    if (txtPIC_NO2.Text.Trim() == "")
                    {
                        ddscDt.setColumnValue("action", "string", "add");
                        ddscDt.setColumnValue("crt_id", "string", LoginUser.VENDOR_NO);
                        ddscDt.setColumnValue("crt_date", "string", SystemDate);
                        ddscDt.setColumnValue("crt_time", "string", SystemTime);
                    }
                    else
                    {
                        ddscDt.setColumnValue("action", "string", "upd");
                        ddscDt.setWhereValue("CODE", txtCODE_SEQ.Text.Trim());
                        ddscDt.setWhereValue("SERIAL_NO", serial);
                    }
                    ddscDt.setColumnValue("CODE", "string", txtCODE_SEQ.Text.Trim());
                    ddscDt.setColumnValue("SERIAL_NO", "string", serial);
                    ddscDt.setColumnValue("DESCRIPTION", "string", this.txtDESCRIPTION2.Text);
                    ddscDt.setColumnValue("status", "string", "1");
                    ddscDt.setColumnValue("upd_id", "string", LoginUser.VENDOR_NO);
                    ddscDt.setColumnValue("upd_date", "string", SystemDate);
                    ddscDt.setColumnValue("upd_time", "string", SystemTime);
                    SERIAL_ARRAY[1] = serial;
                    IMAGE_ARRAY[1] = ImageData;
                }

                if (txtPIC_NO3.Text.Trim() != "")
                {
                    serial = txtPIC_NO3.Text.Trim();
                }
                else
                {
                    ds = Query_Serial(txtCODE_SEQ.Text);
                    if (!(ds == null) && ds.Tables["info"].Rows[0]["ReturnCode"] != "100" && ds.Tables["info"].Rows[0]["ReturnCode"] != "999")
                    {
                        if (!(ds.Tables["B2B_MATERIAL_IMAGE_SEQUENCE"] == null))
                        {
                            serial = ds.Tables["B2B_MATERIAL_IMAGE_SEQUENCE"].Rows[0]["serial_no"].ToString();
                            _num = this.getSerialNum(serial);
                            if (_num > 9)
                            {
                                serial = txtCODE_SEQ.Text.Trim() + "_" + _num;
                            }
                            else
                            {
                                serial = txtCODE_SEQ.Text.Trim() + "_" + "0" + _num;

                            }
                        }
                        else
                        {
                            _num = this.getSerialNum(serial);
                            serial = txtCODE_SEQ.Text.Trim() + "_" + "0" + _num;
                        }

                    }
                    else
                    {
                        serial = txtCODE_SEQ.Text.Trim() + "_" + "01";
                    }
                }
                if ((this.txtPATH3.Value != "" && this.chkDEL3.Checked == false) || this.txtDESCRIPTION3.Text != "")
                {
                    int bufSize = (int)this.txtPATH3.PostedFile.InputStream.Length;
                    byte[] ImageData = new byte[bufSize + 1];
                    int bytesRead = this.txtPATH3.PostedFile.InputStream.Read(ImageData, 0, bufSize);
                    string strSQL;

                    ddscDt.addNewRow();
                    // 設定dscDt各欄位Value，參數一：columnName,參數二：columnValue
                    if (txtPIC_NO3.Text.Trim() == "")
                    {
                        ddscDt.setColumnValue("action", "string", "add");
                        ddscDt.setColumnValue("crt_id", "string", LoginUser.VENDOR_NO);
                        ddscDt.setColumnValue("crt_date", "string", SystemDate);
                        ddscDt.setColumnValue("crt_time", "string", SystemTime);
                    }
                    else
                    {
                        ddscDt.setColumnValue("action", "string", "upd");
                        ddscDt.setWhereValue("CODE", txtCODE_SEQ.Text.Trim());
                        ddscDt.setWhereValue("SERIAL_NO", serial);
                    }
                    ddscDt.setColumnValue("CODE", "string", txtCODE_SEQ.Text.Trim());
                    ddscDt.setColumnValue("SERIAL_NO", "string", serial);
                    ddscDt.setColumnValue("DESCRIPTION", "string", this.txtDESCRIPTION3.Text);
                    ddscDt.setColumnValue("status", "string", "1");
                    ddscDt.setColumnValue("upd_id", "string", LoginUser.VENDOR_NO);
                    ddscDt.setColumnValue("upd_date", "string", SystemDate);
                    ddscDt.setColumnValue("upd_time", "string", SystemTime);
                    SERIAL_ARRAY[2] = serial;
                    IMAGE_ARRAY[2] = ImageData;
                }
                // 新增Row至ddscDt
                //勾選第一筆刪除
                if (this.chkDEL1.Checked)
                {
                    ddscDt.addNewRow();
                    ddscDt.setColumnValue("action", "string", "upd");
                    ddscDt.setColumnValue("SERIAL_NO", "string", txtPIC_NO1.Text.Trim());
                    ddscDt.setColumnValue("status", "string", "0");
                    ddscDt.setColumnValue("upd_id", "string", LoginUser.VENDOR_NO);
                    ddscDt.setColumnValue("upd_date", "string", SystemDate);
                    ddscDt.setColumnValue("upd_time", "string", SystemTime);
                    ddscDt.setWhereValue("SERIAL_NO", txtPIC_NO1.Text.Trim());
                    ddscDt.setWhereValue("CODE", txtCODE_SEQ.Text.Trim());

                    ddscDt.addNewRow();
                    ddscDt.setColumnValue("action", "string", "del");
                    ddscDt.setColumnValue("CODE", "string", txtCODE_SEQ.Text.Trim());
                    ddscDt.setColumnValue("SERIAL_NO", "string", txtPIC_NO1.Text.Trim());
                    ddscDt.setWhereValue("CODE", txtCODE_SEQ.Text.Trim());
                    ddscDt.setWhereValue("SERIAL_NO", txtPIC_NO1.Text.Trim());
                }
                //勾選第二筆刪除
                if (this.chkDEL2.Checked)
                {
                    ddscDt.addNewRow();
                    ddscDt.setColumnValue("action", "string", "upd");
                    ddscDt.setColumnValue("SERIAL_NO", "string", txtPIC_NO2.Text.Trim());
                    ddscDt.setColumnValue("status", "string", "0");
                    ddscDt.setColumnValue("upd_id", "string", LoginUser.VENDOR_NO);
                    ddscDt.setColumnValue("upd_date", "string", SystemDate);
                    ddscDt.setColumnValue("upd_time", "string", SystemTime);
                    ddscDt.setWhereValue("SERIAL_NO", txtPIC_NO2.Text.Trim());
                    ddscDt.setWhereValue("CODE", txtCODE_SEQ.Text.Trim());

                    ddscDt.addNewRow();
                    ddscDt.setColumnValue("action", "string", "del");
                    ddscDt.setColumnValue("CODE", "string", txtCODE_SEQ.Text.Trim());
                    ddscDt.setColumnValue("SERIAL_NO", "string", txtPIC_NO2.Text.Trim());
                    ddscDt.setWhereValue("CODE", txtCODE_SEQ.Text.Trim());
                    ddscDt.setWhereValue("SERIAL_NO", txtPIC_NO2.Text.Trim());
                }
                //勾選第三筆刪除
                if (this.chkDEL3.Checked)
                {
                    ddscDt.addNewRow();
                    ddscDt.setColumnValue("action", "string", "upd");
                    ddscDt.setColumnValue("SERIAL_NO", "string", txtPIC_NO3.Text.Trim());
                    ddscDt.setColumnValue("status", "string", "0");
                    ddscDt.setColumnValue("upd_id", "string", LoginUser.VENDOR_NO);
                    ddscDt.setColumnValue("upd_date", "string", SystemDate);
                    ddscDt.setColumnValue("upd_time", "string", SystemTime);
                    ddscDt.setWhereValue("SERIAL_NO", txtPIC_NO3.Text.Trim());
                    ddscDt.setWhereValue("CODE", txtCODE_SEQ.Text.Trim());
                    ddscDt.addNewRow();
                    ddscDt.setColumnValue("action", "string", "del");
                    ddscDt.setColumnValue("CODE", "string", txtCODE_SEQ.Text.Trim());
                    ddscDt.setColumnValue("SERIAL_NO", "string", txtPIC_NO3.Text.Trim());
                    ddscDt.setWhereValue("CODE", txtCODE_SEQ.Text.Trim());
                    ddscDt.setWhereValue("SERIAL_NO", txtPIC_NO3.Text.Trim());
                }


                //Update S8970025
                com.ddsc.common.ddscDataTable ddscDt_SUPPLY = ddscDs.createDataTable("B2B_SUPPLY");

                ddscDt_SUPPLY.addNewRow();
                // 設定dscDt各欄位Value，參數一：columnName,參數二：columnValue
                ddscDt_SUPPLY.setColumnValue("action", "string", "add");
                ddscDt_SUPPLY.setColumnValue("VENDOR_NO", "string", LoginUser.VENDOR_NO);
                ddscDt_SUPPLY.setColumnValue("CODE", "string", txtCODE_SEQ.Text.Trim());
                ddscDt_SUPPLY.setColumnValue("MINNUM_QTY", "string", txtMINNUM_QTY.Text.Trim());
                ddscDt_SUPPLY.setColumnValue("SUPPLY_UNIT", "string", drpPACKAGE_UNIT.SelectedValue);

                ddscDt_SUPPLY.setColumnValue("SUPPLY_PRICE", "string", this.txtSUPPLY_PRICE.Text.Trim());
                ddscDt_SUPPLY.setColumnValue("ADVISED_PRICE", "string", this.txtADVISED_PRICE.Text.Trim());
                ddscDt_SUPPLY.setColumnValue("AVERAGE_PRICE", "string", this.txtAVERAGE_PRICE.Text.Trim());
                ddscDt_SUPPLY.setColumnValue("DUTY_FREE_PRICE", "string", this.txtDUTY_FREE_PRICE.Text.Trim());
                ddscDt_SUPPLY.setColumnValue("PRICE_CHANGE_DATE", "string", SystemDate);
                ddscDt_SUPPLY.setColumnValue("CURRENCY_TYPE", "string", this.drpCURRENCY_TYPE.SelectedValue.Trim());
                ddscDt_SUPPLY.setColumnValue("ADVISED_CURRENCY_TYPE", "string", this.drpADVISED_CURRENCY_TYPE.SelectedValue.Trim());
                ddscDt_SUPPLY.setColumnValue("AVERAGE_CURRENCY_TYPE", "string", this.drpAVERAGE_CURRENCY_TYPE.SelectedValue.Trim());
                ddscDt_SUPPLY.setColumnValue("DUTY_FREE_CURRENCY_TYPE", "string", this.drpDUTY_FREE_CURRENCY_TYPE.SelectedValue.Trim());

                //Leo Add 20090729 增加五個欄位
                ddscDt_SUPPLY.setColumnValue("PROD_INFO_CHINESE", "string", this.txtPROD_INFO_CHINESE.Text.ToString());
                ddscDt_SUPPLY.setColumnValue("PROD_INFO_ENGLISH", "string", this.txtPROD_INFO_ENGLISH.Text.ToString());
                ddscDt_SUPPLY.setColumnValue("PROD_SPEC_CHINESE", "string", this.txtPROD_SPEC_CHINESE.Text.ToString());
                ddscDt_SUPPLY.setColumnValue("PROD_SPEC_ENGLISH", "string", this.txtPROD_SPEC_ENGLISH.Text.ToString());
                ddscDt_SUPPLY.setColumnValue("BRAND_ID", "string", this.drpBRAND_ID.SelectedValue.Trim());
                //Leo add end
                //P3109m0050


                string DELIVERY_TERM = "";

                //If drpDELIVERY_TERM.SelectedValue = "FOB_Seaport" Then
                //    DELIVERY_TERM = drpDELIVERY_TERM.SelectedValue & Me.txtSEAPORT.Text
                //Else
                //    DELIVERY_TERM = drpDELIVERY_TERM.SelectedValue
                //End If
                //DELIVERY_TERM = txtDELIVERY_TERM.Text 20100901 JAFF MARK
                //20100901 JAFF add
                if (drpDELIVERY_TERM.SelectedValue == "")
                {
                    DELIVERY_TERM = txtSEAPORT.Text;
                }
                else
                {
                    DELIVERY_TERM = drpDELIVERY_TERM.SelectedValue + "_" + txtSEAPORT.Text;
                }
                //----------------------------------
                ddscDt_SUPPLY.setColumnValue("DELIVERY_TERM", "string", DELIVERY_TERM);
                ddscDt_SUPPLY.setColumnValue("PAYMENT_TERM_NO", "string", this.drpPAYMENT_TERM_NO.SelectedValue.Trim());
                ddscDt_SUPPLY.setColumnValue("QUOTATION_VALID_DATE", "string", this.txtQUOTATION_VALID_DATE.Text.Trim());
                ddscDt_SUPPLY.setColumnValue("CLERK", "string", this.txtCLERK.Text.Trim());
                ddscDt_SUPPLY.setColumnValue("CLERK_TEL", "string", this.txtCLERK_TEL.Text.Trim());
                ddscDt_SUPPLY.setColumnValue("ORIGINAL_CODE", "string", txtCODE_SEQ.Text.Trim());

                ddscDt_SUPPLY.setColumnValue("status", "string", "1");
                ddscDt_SUPPLY.setColumnValue("upd_id", "string", LoginUser.VENDOR_NO);
                ddscDt_SUPPLY.setColumnValue("upd_date", "string", SystemDate);
                ddscDt_SUPPLY.setColumnValue("upd_time", "string", SystemTime);
                ddscDt_SUPPLY.setColumnValue("crt_id", "string", LoginUser.VENDOR_NO);
                ddscDt_SUPPLY.setColumnValue("crt_date", "string", SystemDate);
                ddscDt_SUPPLY.setColumnValue("crt_time", "string", SystemTime);


                com.ddsc.common.ddscDataTable ddscDt_SUPPLY_LOG = ddscDs.createDataTable("B2B_SUPPLY_LOG");
                ddscDt_SUPPLY_LOG.addNewRow();
                // 設定dscDt各欄位Value，參數一：columnName,參數二：columnValue
                FunctionHandler FunctionHandler = new FunctionHandler();
                string Log_Serial = FunctionHandler.getB2BSerialNo("SU", "LOG", DateTime.Today.ToString("yy"), 5);
                ddscDt_SUPPLY_LOG.setColumnValue("action", "string", "add");
                ddscDt_SUPPLY_LOG.setColumnValue("SEQ_NO", "string", Log_Serial);
                ddscDt_SUPPLY_LOG.setColumnValue("CODE", "string", txtCODE_SEQ.Text.Trim());
                ddscDt_SUPPLY_LOG.setColumnValue("VENDOR_NO", "string", LoginUser.VENDOR_NO);
                ddscDt_SUPPLY_LOG.setColumnValue("MINNUM_QTY", "string", txtMINNUM_QTY.Text.Trim());

                ddscDt_SUPPLY_LOG.setColumnValue("DELIVERY_TERM", "string", DELIVERY_TERM);
                ddscDt_SUPPLY_LOG.setColumnValue("PAYMENT_TERM_NO", "string", this.drpPAYMENT_TERM_NO.SelectedValue.Trim());
                ddscDt_SUPPLY_LOG.setColumnValue("CURRENCY_TYPE", "string", this.drpCURRENCY_TYPE.SelectedValue.Trim());
                ddscDt_SUPPLY_LOG.setColumnValue("SUPPLY_PRICE", "string", this.txtSUPPLY_PRICE.Text.Trim());
                ddscDt_SUPPLY_LOG.setColumnValue("ADVISED_PRICE", "string", this.txtADVISED_PRICE.Text.Trim());
                ddscDt_SUPPLY_LOG.setColumnValue("AVERAGE_PRICE", "string", this.txtAVERAGE_PRICE.Text.Trim());
                ddscDt_SUPPLY_LOG.setColumnValue("DUTY_FREE_PRICE", "string", this.txtDUTY_FREE_PRICE.Text.Trim());
                ddscDt_SUPPLY_LOG.setColumnValue("PACKAGE_UNIT", "string", drpPACKAGE_UNIT.SelectedValue);
                ddscDt_SUPPLY_LOG.setColumnValue("STORE_UNIT", "string", this.drpPACKAGE_UNIT.SelectedValue.Trim());
                ddscDt_SUPPLY_LOG.setColumnValue("COEFFICIENT", "string", this.txtCOEFFICIENT.Text.Trim());
                ddscDt_SUPPLY_LOG.setColumnValue("QUOTATION_VALID_DATE", "string", this.txtQUOTATION_VALID_DATE.Text.Trim());
                ddscDt_SUPPLY_LOG.setColumnValue("CLERK", "string", this.txtCLERK.Text.Trim());
                ddscDt_SUPPLY_LOG.setColumnValue("CLERK_TEL", "string", this.txtCLERK_TEL.Text.Trim());
                ddscDt_SUPPLY_LOG.setColumnValue("ORIGINAL_CODE", "string", txtCODE_SEQ.Text.Trim());

                ddscDt_SUPPLY_LOG.setColumnValue("status", "string", "1");
                ddscDt_SUPPLY_LOG.setColumnValue("upd_id", "string", LoginUser.VENDOR_NO);
                ddscDt_SUPPLY_LOG.setColumnValue("upd_date", "string", SystemDate);
                ddscDt_SUPPLY_LOG.setColumnValue("upd_time", "string", SystemTime);
                ddscDt_SUPPLY_LOG.setColumnValue("crt_id", "string", LoginUser.VENDOR_NO);
                ddscDt_SUPPLY_LOG.setColumnValue("crt_date", "string", SystemDate);
                ddscDt_SUPPLY_LOG.setColumnValue("crt_time", "string", SystemTime);

                //'Leo Add 20090729 增加五個欄位
                //ddscDt_SUPPLY_LOG.setColumnValue("PROD_INFO_CHINESE", "string", Me.txtPROD_INFO_CHINESE.Text.ToString)
                //ddscDt_SUPPLY_LOG.setColumnValue("PROD_INFO_ENGLISH", "string", Me.txtPROD_INFO_ENGLISH.Text.ToString)
                //ddscDt_SUPPLY_LOG.setColumnValue("PROD_SPEC_CHINESE", "string", Me.txtPROD_SPEC_CHINESE.Text.ToString)
                //ddscDt_SUPPLY_LOG.setColumnValue("PROD_SPEC_ENGLISH", "string", Me.txtPROD_SPEC_ENGLISH.Text.ToString)
                //ddscDt_SUPPLY_LOG.setColumnValue("BRAND_ID", "string", Me.drpBRAND_ID.SelectedValue.Trim())
                //'Leo add end


                ddscDs.addDataTable(ddscDt_SUPPLY_LOG);
                ddscDs.addDataTable(ddscDt_SUPPLY);
                ddscDs.addDataTable(ddscDt);
                ddscDs.addDataTable(ddscD);
                // 執行新增method


                string MailTo = "";
                string SelectCommand = string.Format("select APPLICANT,b.EMAIL from  VND_RELATED_USER A,psn_open_data B WHERE VENDOR_KIND=\'{0}\' and a.APPLICANT=b.EMPLOYEE_NO(+)", LoginUser.VENDOR_KIND);
                ds = DataBase.Query_CLASS(SelectCommand, "VND_RELATED_USER");
                int Row = 0;
                if (!(ds == null) && ds.Tables["info"].Rows[0]["ReturnCode"] != "100" && ds.Tables["info"].Rows[0]["ReturnCode"] != "999")
                {
                    for (Row = 0; Row <= ds.Tables["VND_RELATED_USER"].Rows.Count - 1; Row++)
                    {
                        //MailTo = MailTo + ds.Tables["VND_RELATED_USER"].Rows[Row]["EMAIL"].ToString() + ";";


                        //fix mail from AD by employeeid
                        string empID = ds.Tables["VND_RELATED_USER"].Rows[Row]["APPLICANT"].ToString();

                        MailTo = MailTo + (new FunctionHandler()).QueryADInfo(empID, ADQueryType.Email) + ";";
                    }

                }
                string BODY = "";
                string Subject = "";

                SelectCommand = string.Format("SELECT M.CONFIG_TYPE,D.CONFIG_CHINESE_DESC,D.CONFIG_ENGLISH_DESC,D.CONFIG_VALUE FROM BAS_REFERENCE_DATA_MASTER M,BAS_REFERENCE_DATA_DETAILS D where M.CONFIG_TYPE=D.CONFIG_TYPE(+) and M.CONFIG_TYPE=\'B2B_VNDR\' and D.CONFIG_KEY=\'NEW_CODE\'");
                ds = DataBase.Query_CLASS(SelectCommand, "BAS_REFERENCE_DATA_MASTER");
                if (!(ds == null) && ds.Tables["info"].Rows[0]["ReturnCode"] != "100" && ds.Tables["info"].Rows[0]["ReturnCode"] != "999")
                {
                    for (Row = 0; Row <= ds.Tables["BAS_REFERENCE_DATA_MASTER"].Rows.Count - 1; Row++)
                    {
                        BODY = System.Convert.ToString(ds.Tables["BAS_REFERENCE_DATA_MASTER"].Rows[Row]["CONFIG_CHINESE_DESC"].ToString().Replace("XXXX", " " + LoginUser.VENDOR_NO + "-" + LoginUser.ENGLISH_NAME + " "));
                        Subject = System.Convert.ToString(ds.Tables["BAS_REFERENCE_DATA_MASTER"].Rows[Row]["CONFIG_VALUE"].ToString().Replace("XXXX", " " + LoginUser.VENDOR_NO + "-" + LoginUser.ENGLISH_NAME + " "));

                    }

                }
                FunctionHandler.SentMail(Subject, MailTo, "", "", "EVAAIR Procurement Information <emilyli@evaair.com>", BODY);




                //dsResult = Update(ddscDs)
                dsResult = DataBase.Addition(ddscDs, "", (System.Array)null, (System.Array)null);

                FunctionHandler.InsertMATERIAL_IMAGE(txtCODE_SEQ.Text, SERIAL_ARRAY, IMAGE_ARRAY);

                // 寫入script至client端
                //  regScript_MATERIAL_maintain(dsResult, "add")
                regScript(dsResult, "add");
                CLEAN();
                // regScript(dsResult, "add")
            }
            catch (System.Data.OracleClient.OracleException ev)
            {
                showException(ev.Message);
            }
            catch (Exception ex)
            {
                showException(ex.Message);
            }
            finally
            {
                // myConnection.Close()
            }

        }

        private int getSerialNum(string serial)
        {

            if (serial.Length >= 2)
            {
                return int.Parse(serial.Substring(serial.Length - 2, 2)) + 1;
            }
            else
            {
                return int.Parse(serial) + 1;
            }
        }

        private void updMATERIAL(string type)
        {
            // 設定傳送的 DataSet 物件
            com.ddsc.common.ddscDataSet ddscDs = new com.ddsc.common.ddscDataSet();

            VENDOR LoginUser = default(VENDOR);
            string VENDOR_NO = "";
            if (this.Request["action_type"].ToString() == "SMAS")
            {
                VENDOR_NO = "SMAS";
            }
            else
            {
                LoginUser = GetLoginUser();
                VENDOR_NO = LoginUser.VENDOR_NO;
            }
            string[] SERIAL_ARRAY = new string[3];
            ArrayList IMAGE_ARRAY = new ArrayList(2);
            byte[] temp = new byte[1];
            IMAGE_ARRAY.Insert(0, temp);
            IMAGE_ARRAY.Insert(1, temp);
            IMAGE_ARRAY.Insert(2, temp);
            // 宣告回傳DataSet
            DataSet dsResult = new DataSet();
            try
            {
                //基本資料

                com.ddsc.common.ddscDataTable ddscD = ddscDs.createDataTable("B2B_MATERIAL");
                // 新增Row至ddscD
                ddscD.addNewRow();
                // 設定dscDt各欄位Value，參數一：columnName,參數二：columnValue
                ddscD.setColumnValue("action", "string", "upd");
                ddscD.setColumnValue("PURCHASE_NO", "string", txtPURCHASE_NO.Text.Trim());
                //P3109M0050 修改B2B新品資料名稱可輸入 '  造成後續新品報價修改產生錯誤之問題    -  By Joe
                ddscD.setColumnValue("ENGLISH_SHORTNAME", "string", System.Convert.ToString(txtENGLISH_SHORTNAME.Text.Trim().Replace("\'", " ")));
                ddscD.setColumnValue("ENGLISH_FULLNAME", "string", System.Convert.ToString(txtENGLISH_FULLNAME.Text.Trim().Replace("\'", " ")));
                ddscD.setColumnValue("CHINESE_SHORTNAME", "string", System.Convert.ToString(this.txtCHINESE_SHORTNAME.Text.Trim().Replace("\'", " ")));
                ddscD.setColumnValue("CHINESE_FULLNAME", "string", System.Convert.ToString(this.txtCHINESE_FULLNAME.Text.Trim().Replace("\'", " ")));

                //P3109M0050
                ddscD.setColumnValue("MATERIAL_TYPE", "string", rdoMATERIAL_TYPE.SelectedValue);
                ddscD.setColumnValue("CLASS", "string", this.hidCLASS.Value);
                ddscD.setColumnValue("CONSIGNED", "string", rdoCONSIGNED.SelectedValue);
                ddscD.setColumnValue("LEAD_TIME", "string", this.txtLEAD_TIME.Text.Trim());
                ddscD.setColumnValue("EXP_DATE", "string", this.txtEXP_DATELINE.Text.Trim());
                ddscD.setColumnValue("PACKAGE_UNIT", "string", drpPACKAGE_UNIT.SelectedValue.Trim());
                ddscD.setColumnValue("STORE_UNIT", "string", this.drpPACKAGE_UNIT.SelectedValue.Trim());
                ddscD.setColumnValue("COEFFICIENT", "string", this.txtCOEFFICIENT.Text.Trim());
                ddscD.setColumnValue("PACK_DETAIL", "string", this.txtPACK_DETAIL.Text.Trim());
                ddscD.setColumnValue("DIMENSION_L", "string", this.txtDIMENSION_L.Text.Trim());
                ddscD.setColumnValue("DIMENSION_W", "string", this.txtDIMENSION_W.Text.Trim());
                ddscD.setColumnValue("DIMENSION_H", "string", this.txtDIMENSION_H.Text.Trim());
                ddscD.setColumnValue("GROSS_WEIGHT", "string", this.txtGROSS_WEIGHT.Text.Trim());

                // Joe Mark 2009/01/22
                // ddscD.setColumnValue("VENDOR_NO", "string", VENDOR_NO)



                //Update S8970025
                ddscD.setColumnValue("ORIGINAL_CODE", "string", this.txtCODE_SEQ.Text);
                ddscD.setColumnValue("NOTE", "string", this.txtNOTE.Text.Trim());


                ddscD.setColumnValue("status", "string", "1");
                ddscD.setColumnValue("upd_id", "string", VENDOR_NO);
                ddscD.setColumnValue("upd_date", "string", SystemDate);
                ddscD.setColumnValue("upd_time", "string", SystemTime);
                ddscD.setWhereValue("CODE", this.txtCODE_SEQ.Text);
                com.ddsc.common.ddscDataTable ddscDt = ddscDs.createDataTable("B2B_MATERIAL_IMAGE_SEQUENCE");
                int _num = 0;
                string serial = System.Convert.ToString(0);
                if (txtPIC_NO1.Text.Trim() != "")
                {
                    serial = txtPIC_NO1.Text.Trim();
                }
                else
                {
                    DataSet ds = Query_Serial(txtCODE_SEQ.Text);
                    if (!(ds == null) && ds.Tables["info"].Rows[0]["ReturnCode"] != "100" && ds.Tables["info"].Rows[0]["ReturnCode"] != "999")
                    {
                        if (!(ds.Tables["B2B_MATERIAL_IMAGE_SEQUENCE"] == null))
                        {
                            serial = ds.Tables["B2B_MATERIAL_IMAGE_SEQUENCE"].Rows[0]["serial_no"].ToString();
                            _num = getSerialNum(serial);
                            if (_num > 9)
                            {
                                serial = txtCODE_SEQ.Text.Trim() + "_" + _num;
                            }
                            else
                            {
                                serial = txtCODE_SEQ.Text.Trim() + "_" + "0" + _num;
                            }
                        }
                        else
                        {
                            _num = getSerialNum(serial);
                            serial = txtCODE_SEQ.Text.Trim() + "_" + "0" + _num;
                        }

                    }
                    else
                    {
                        serial = txtCODE_SEQ.Text.Trim() + "_" + "01";
                    }
                }
                if ((this.txtPATH1.Value != "" && this.chkDEL1.Checked == false) || this.txtDESCRIPTION1.Text != "")
                {
                    int bufSize = System.Convert.ToInt32(this.txtPATH1.PostedFile.InputStream.Length - 1);
                    byte[] ImageData = new byte[bufSize + 1];
                    int bytesRead = this.txtPATH1.PostedFile.InputStream.Read(ImageData, 0, bufSize);
                    string strSQL;

                    ddscDt.addNewRow();
                    // 設定dscDt各欄位Value，參數一：columnName,參數二：columnValue
                    if (txtPIC_NO1.Text.Trim() == "")
                    {
                        ddscDt.setColumnValue("action", "string", "add");
                        ddscDt.setColumnValue("crt_id", "string", VENDOR_NO);
                        ddscDt.setColumnValue("crt_date", "string", SystemDate);
                        ddscDt.setColumnValue("crt_time", "string", SystemTime);
                    }
                    else
                    {
                        ddscDt.setColumnValue("action", "string", "upd");
                        ddscDt.setWhereValue("CODE", txtCODE_SEQ.Text.Trim());
                        ddscDt.setWhereValue("SERIAL_NO", serial);
                    }
                    ddscDt.setColumnValue("CODE", "string", txtCODE_SEQ.Text.Trim());
                    ddscDt.setColumnValue("SERIAL_NO", "string", serial);
                    ddscDt.setColumnValue("DESCRIPTION", "string", this.txtDESCRIPTION1.Text);
                    ddscDt.setColumnValue("status", "string", "1");
                    ddscDt.setColumnValue("upd_id", "string", VENDOR_NO);
                    ddscDt.setColumnValue("upd_date", "string", SystemDate);
                    ddscDt.setColumnValue("upd_time", "string", SystemTime);
                    SERIAL_ARRAY[0] = serial;
                    IMAGE_ARRAY[0] = ImageData;
                }

                if (txtPIC_NO2.Text.Trim() != "")
                {
                    serial = txtPIC_NO2.Text.Trim();
                }
                else
                {
                    DataSet ds = Query_Serial(txtCODE_SEQ.Text);
                    if (!(ds == null) && ds.Tables["info"].Rows[0]["ReturnCode"] != "100" && ds.Tables["info"].Rows[0]["ReturnCode"] != "999")
                    {
                        if (!(ds.Tables["B2B_MATERIAL_IMAGE_SEQUENCE"] == null))
                        {
                            serial = ds.Tables["B2B_MATERIAL_IMAGE_SEQUENCE"].Rows[0]["serial_no"].ToString();
                            _num = getSerialNum(serial);
                            if (_num > 9)
                            {
                                serial = txtCODE_SEQ.Text.Trim() + "_" + _num;
                            }
                            else
                            {
                                serial = txtCODE_SEQ.Text.Trim() + "_" + "0" + _num;
                            }
                        }
                        else
                        {
                            _num = getSerialNum(serial);
                            serial = txtCODE_SEQ.Text.Trim() + "_" + "0" + _num;
                        }

                    }
                    else
                    {
                        serial = txtCODE_SEQ.Text.Trim() + "_" + "01";
                    }
                }
                if ((this.txtPATH2.Value != "" && this.chkDEL2.Checked == false) || this.txtDESCRIPTION2.Text != "")
                {
                    int bufSize = System.Convert.ToInt32(this.txtPATH2.PostedFile.InputStream.Length - 1);
                    byte[] ImageData = new byte[bufSize + 1];
                    int bytesRead = this.txtPATH2.PostedFile.InputStream.Read(ImageData, 0, bufSize);
                    string strSQL;

                    ddscDt.addNewRow();
                    // 設定dscDt各欄位Value，參數一：columnName,參數二：columnValue
                    if (txtPIC_NO2.Text.Trim() == "")
                    {
                        ddscDt.setColumnValue("action", "string", "add");
                        ddscDt.setColumnValue("crt_id", "string", VENDOR_NO);
                        ddscDt.setColumnValue("crt_date", "string", SystemDate);
                        ddscDt.setColumnValue("crt_time", "string", SystemTime);
                    }
                    else
                    {
                        ddscDt.setColumnValue("action", "string", "upd");
                        ddscDt.setWhereValue("CODE", txtCODE_SEQ.Text.Trim());
                        ddscDt.setWhereValue("SERIAL_NO", serial);
                    }
                    ddscDt.setColumnValue("CODE", "string", txtCODE_SEQ.Text.Trim());
                    ddscDt.setColumnValue("SERIAL_NO", "string", serial);
                    ddscDt.setColumnValue("DESCRIPTION", "string", this.txtDESCRIPTION2.Text);
                    ddscDt.setColumnValue("status", "string", "1");
                    ddscDt.setColumnValue("upd_id", "string", VENDOR_NO);
                    ddscDt.setColumnValue("upd_date", "string", SystemDate);
                    ddscDt.setColumnValue("upd_time", "string", SystemTime);
                    SERIAL_ARRAY[1] = serial;
                    IMAGE_ARRAY[1] = ImageData;
                }

                if (txtPIC_NO3.Text.Trim() != "")
                {
                    serial = txtPIC_NO3.Text.Trim();
                }
                else
                {
                    DataSet ds = Query_Serial(txtCODE_SEQ.Text);
                    if (!(ds == null) && ds.Tables["info"].Rows[0]["ReturnCode"] != "100" && ds.Tables["info"].Rows[0]["ReturnCode"] != "999")
                    {
                        if (!(ds.Tables["B2B_MATERIAL_IMAGE_SEQUENCE"] == null))
                        {
                            serial = ds.Tables["B2B_MATERIAL_IMAGE_SEQUENCE"].Rows[0]["serial_no"].ToString();
                            _num = getSerialNum(serial);
                            if (_num > 9)
                            {
                                serial = txtCODE_SEQ.Text.Trim() + "_" + _num;
                            }
                            else
                            {
                                serial = txtCODE_SEQ.Text.Trim() + "_" + "0" + _num;
                            }
                        }
                        else
                        {
                            _num = getSerialNum(serial);
                            serial = txtCODE_SEQ.Text.Trim() + "_" + "0" + _num;
                        }

                    }
                    else
                    {
                        serial = txtCODE_SEQ.Text.Trim() + "_" + "01";
                    }
                }
                if ((this.txtPATH3.Value != "" && this.chkDEL3.Checked == false) || this.txtDESCRIPTION3.Text != "")
                {
                    int bufSize = System.Convert.ToInt32(this.txtPATH3.PostedFile.InputStream.Length - 1);
                    byte[] ImageData = new byte[bufSize + 1];
                    int bytesRead = this.txtPATH3.PostedFile.InputStream.Read(ImageData, 0, bufSize);
                    string strSQL;

                    ddscDt.addNewRow();
                    // 設定dscDt各欄位Value，參數一：columnName,參數二：columnValue
                    if (txtPIC_NO3.Text.Trim() == "")
                    {
                        ddscDt.setColumnValue("action", "string", "add");
                        ddscDt.setColumnValue("crt_id", "string", VENDOR_NO);
                        ddscDt.setColumnValue("crt_date", "string", SystemDate);
                        ddscDt.setColumnValue("crt_time", "string", SystemTime);
                    }
                    else
                    {
                        ddscDt.setColumnValue("action", "string", "upd");
                        ddscDt.setWhereValue("CODE", txtCODE_SEQ.Text.Trim());
                        ddscDt.setWhereValue("SERIAL_NO", serial);
                    }
                    ddscDt.setColumnValue("CODE", "string", txtCODE_SEQ.Text.Trim());
                    ddscDt.setColumnValue("SERIAL_NO", "string", serial);
                    ddscDt.setColumnValue("DESCRIPTION", "string", this.txtDESCRIPTION3.Text);
                    ddscDt.setColumnValue("status", "string", "1");
                    ddscDt.setColumnValue("upd_id", "string", VENDOR_NO);
                    ddscDt.setColumnValue("upd_date", "string", SystemDate);
                    ddscDt.setColumnValue("upd_time", "string", SystemTime);
                    SERIAL_ARRAY[2] = serial;
                    IMAGE_ARRAY[2] = ImageData;
                }
                // 新增Row至ddscDt
                //勾選第一筆刪除
                if (this.chkDEL1.Checked)
                {
                    ddscDt.addNewRow();
                    ddscDt.setColumnValue("action", "string", "upd");
                    ddscDt.setColumnValue("SERIAL_NO", "string", txtPIC_NO1.Text.Trim());
                    ddscDt.setColumnValue("status", "string", "0");
                    ddscDt.setColumnValue("upd_id", "string", VENDOR_NO);
                    ddscDt.setColumnValue("upd_date", "string", SystemDate);
                    ddscDt.setColumnValue("upd_time", "string", SystemTime);
                    ddscDt.setWhereValue("SERIAL_NO", txtPIC_NO1.Text.Trim());
                    ddscDt.setWhereValue("CODE", txtCODE_SEQ.Text.Trim());

                    ddscDt.addNewRow();
                    ddscDt.setColumnValue("action", "string", "del");
                    ddscDt.setColumnValue("CODE", "string", txtCODE_SEQ.Text.Trim());
                    ddscDt.setColumnValue("SERIAL_NO", "string", txtPIC_NO1.Text.Trim());
                    ddscDt.setWhereValue("CODE", txtCODE_SEQ.Text.Trim());
                    ddscDt.setWhereValue("SERIAL_NO", txtPIC_NO1.Text.Trim());
                }
                //勾選第二筆刪除
                if (this.chkDEL2.Checked)
                {
                    ddscDt.addNewRow();
                    ddscDt.setColumnValue("action", "string", "upd");
                    ddscDt.setColumnValue("SERIAL_NO", "string", txtPIC_NO2.Text.Trim());
                    ddscDt.setColumnValue("status", "string", "0");
                    ddscDt.setColumnValue("upd_id", "string", VENDOR_NO);
                    ddscDt.setColumnValue("upd_date", "string", SystemDate);
                    ddscDt.setColumnValue("upd_time", "string", SystemTime);
                    ddscDt.setWhereValue("SERIAL_NO", txtPIC_NO2.Text.Trim());
                    ddscDt.setWhereValue("CODE", txtCODE_SEQ.Text.Trim());

                    ddscDt.addNewRow();
                    ddscDt.setColumnValue("action", "string", "del");
                    ddscDt.setColumnValue("CODE", "string", txtCODE_SEQ.Text.Trim());
                    ddscDt.setColumnValue("SERIAL_NO", "string", txtPIC_NO2.Text.Trim());
                    ddscDt.setWhereValue("CODE", txtCODE_SEQ.Text.Trim());
                    ddscDt.setWhereValue("SERIAL_NO", txtPIC_NO2.Text.Trim());
                }
                //勾選第三筆刪除
                if (this.chkDEL3.Checked)
                {
                    ddscDt.addNewRow();
                    ddscDt.setColumnValue("action", "string", "upd");
                    ddscDt.setColumnValue("SERIAL_NO", "string", txtPIC_NO3.Text.Trim());
                    ddscDt.setColumnValue("status", "string", "0");
                    ddscDt.setColumnValue("upd_id", "string", VENDOR_NO);
                    ddscDt.setColumnValue("upd_date", "string", SystemDate);
                    ddscDt.setColumnValue("upd_time", "string", SystemTime);
                    ddscDt.setWhereValue("SERIAL_NO", txtPIC_NO3.Text.Trim());
                    ddscDt.setWhereValue("CODE", txtCODE_SEQ.Text.Trim());
                    ddscDt.addNewRow();
                    ddscDt.setColumnValue("action", "string", "del");
                    ddscDt.setColumnValue("CODE", "string", txtCODE_SEQ.Text.Trim());
                    ddscDt.setColumnValue("SERIAL_NO", "string", txtPIC_NO3.Text.Trim());
                    ddscDt.setWhereValue("CODE", txtCODE_SEQ.Text.Trim());
                    ddscDt.setWhereValue("SERIAL_NO", txtPIC_NO3.Text.Trim());
                }

                //Update S8970025
                com.ddsc.common.ddscDataTable ddscDt_SUPPLY = ddscDs.createDataTable("B2B_SUPPLY");

                ddscDt_SUPPLY.addNewRow();
                // 設定dscDt各欄位Value，參數一：columnName,參數二：columnValue
                ddscDt_SUPPLY.setColumnValue("action", "string", "upd");
                ddscDt_SUPPLY.setColumnValue("VENDOR_NO", "string", VENDOR_NO);
                ddscDt_SUPPLY.setColumnValue("CODE", "string", txtCODE_SEQ.Text.Trim());
                ddscDt_SUPPLY.setColumnValue("MINNUM_QTY", "string", txtMINNUM_QTY.Text.Trim());
                ddscDt_SUPPLY.setColumnValue("SUPPLY_PRICE", "string", this.txtSUPPLY_PRICE.Text.Trim());
                ddscDt_SUPPLY.setColumnValue("ADVISED_PRICE", "string", this.txtADVISED_PRICE.Text.Trim());
                ddscDt_SUPPLY.setColumnValue("SUPPLY_UNIT", "string", drpPACKAGE_UNIT.SelectedValue);
                ddscDt_SUPPLY.setColumnValue("AVERAGE_PRICE", "string", this.txtAVERAGE_PRICE.Text.Trim());
                ddscDt_SUPPLY.setColumnValue("DUTY_FREE_PRICE", "string", this.txtDUTY_FREE_PRICE.Text.Trim());
                ddscDt_SUPPLY.setColumnValue("PRICE_CHANGE_DATE", "string", SystemDate);
                ddscDt_SUPPLY.setColumnValue("CURRENCY_TYPE", "string", this.drpCURRENCY_TYPE.SelectedValue.Trim());
                ddscDt_SUPPLY.setColumnValue("ADVISED_CURRENCY_TYPE", "string", this.drpADVISED_CURRENCY_TYPE.SelectedValue.Trim());
                ddscDt_SUPPLY.setColumnValue("AVERAGE_CURRENCY_TYPE", "string", this.drpAVERAGE_CURRENCY_TYPE.SelectedValue.Trim());
                ddscDt_SUPPLY.setColumnValue("DUTY_FREE_CURRENCY_TYPE", "string", this.drpDUTY_FREE_CURRENCY_TYPE.SelectedValue.Trim());

                //Leo Add 20090729 增加五個欄位
                ddscDt_SUPPLY.setColumnValue("PROD_INFO_CHINESE", "string", this.txtPROD_INFO_CHINESE.Text.ToString());
                ddscDt_SUPPLY.setColumnValue("PROD_INFO_ENGLISH", "string", this.txtPROD_INFO_ENGLISH.Text.ToString());
                ddscDt_SUPPLY.setColumnValue("PROD_SPEC_CHINESE", "string", this.txtPROD_SPEC_CHINESE.Text.ToString());
                ddscDt_SUPPLY.setColumnValue("PROD_SPEC_ENGLISH", "string", this.txtPROD_SPEC_ENGLISH.Text.ToString());
                ddscDt_SUPPLY.setColumnValue("BRAND_ID", "string", this.drpBRAND_ID.SelectedValue.Trim());
                //Leo add end

                string DELIVERY_TERM = "";

                //If drpDELIVERY_TERM.SelectedValue = "FOB_Seaport" Then
                //    DELIVERY_TERM = drpDELIVERY_TERM.SelectedValue & Me.txtSEAPORT.Text
                //Else
                //    DELIVERY_TERM = drpDELIVERY_TERM.SelectedValue
                //End If
                //DELIVERY_TERM = txtDELIVERY_TERM.Text 20100901 JAFF MARK
                // 20100901 JAFF add
                if (drpDELIVERY_TERM.SelectedValue == "")
                {
                    DELIVERY_TERM = txtSEAPORT.Text;
                }
                else
                {
                    DELIVERY_TERM = drpDELIVERY_TERM.SelectedValue + "_" + txtSEAPORT.Text;
                }
                //-----------------------------
                ddscDt_SUPPLY.setColumnValue("DELIVERY_TERM", "string", DELIVERY_TERM);
                ddscDt_SUPPLY.setColumnValue("PAYMENT_TERM_NO", "string", this.drpPAYMENT_TERM_NO.SelectedValue.Trim());

                ddscDt_SUPPLY.setColumnValue("QUOTATION_VALID_DATE", "string", this.txtQUOTATION_VALID_DATE.Text.Trim());

                ddscDt_SUPPLY.setColumnValue("CLERK", "string", this.txtCLERK.Text.Trim());
                ddscDt_SUPPLY.setColumnValue("CLERK_TEL", "string", this.txtCLERK_TEL.Text.Trim());
                ddscDt_SUPPLY.setColumnValue("ORIGINAL_CODE", "string", txtCODE_SEQ.Text.Trim());

                ddscDt_SUPPLY.setColumnValue("status", "string", "1");
                ddscDt_SUPPLY.setColumnValue("upd_id", "string", VENDOR_NO);
                ddscDt_SUPPLY.setColumnValue("upd_date", "string", SystemDate);
                ddscDt_SUPPLY.setColumnValue("upd_time", "string", SystemTime);
                ddscDt_SUPPLY.setColumnValue("crt_id", "string", VENDOR_NO);
                ddscDt_SUPPLY.setColumnValue("crt_date", "string", SystemDate);
                ddscDt_SUPPLY.setColumnValue("crt_time", "string", SystemTime);
                ddscDt_SUPPLY.setWhereValue("CODE", txtCODE_SEQ.Text.Trim());
                ddscDt_SUPPLY.setWhereValue("VENDOR_NO", VENDOR_NO);

                com.ddsc.common.ddscDataTable ddscDt_SUPPLY_LOG = ddscDs.createDataTable("B2B_SUPPLY_LOG");
                ddscDt_SUPPLY_LOG.addNewRow();
                // 設定dscDt各欄位Value，參數一：columnName,參數二：columnValue
                FunctionHandler FunctionHandler = new FunctionHandler();

                //20100901 JAFF MARK
                // If ((hidPAYMENT_TERM_NO.Value <> Me.drpPAYMENT_TERM_NO.SelectedValue) Or (hidCURRENCY_TYPE.Value <> Me.drpCURRENCY_TYPE.SelectedValue) Or (hidSUPPLY_PRICE.Value <> Me.txtSUPPLY_PRICE.Text) Or (hidDELIVERY_TERM.Value <> Me.txtDELIVERY_TERM.Text)) Then
                if ((hidPAYMENT_TERM_NO.Value != this.drpPAYMENT_TERM_NO.SelectedValue) || (hidCURRENCY_TYPE.Value != this.drpCURRENCY_TYPE.SelectedValue) || (hidSUPPLY_PRICE.Value != this.txtSUPPLY_PRICE.Text) || (hidDELIVERY_TERM.Value != this.drpDELIVERY_TERM.SelectedValue + "_" + txtSEAPORT.Text))
                {

                    string Log_Serial = FunctionHandler.getB2BSerialNo("SU", "LOG", DateTime.Today.ToString("yy"), 5);
                    ddscDt_SUPPLY_LOG.setColumnValue("action", "string", "add");
                    ddscDt_SUPPLY_LOG.setColumnValue("VENDOR_NO", "string", VENDOR_NO);
                    ddscDt_SUPPLY_LOG.setColumnValue("SEQ_NO", "string", Log_Serial);
                    ddscDt_SUPPLY_LOG.setColumnValue("CODE", "string", txtCODE_SEQ.Text.Trim());
                    ddscDt_SUPPLY_LOG.setColumnValue("MINNUM_QTY", "string", txtMINNUM_QTY.Text.Trim());
                    ddscDt_SUPPLY_LOG.setColumnValue("DELIVERY_TERM", "string", DELIVERY_TERM);
                    ddscDt_SUPPLY_LOG.setColumnValue("PAYMENT_TERM_NO", "string", this.drpPAYMENT_TERM_NO.SelectedValue.Trim());
                    ddscDt_SUPPLY_LOG.setColumnValue("CURRENCY_TYPE", "string", this.drpCURRENCY_TYPE.SelectedValue.Trim());
                    ddscDt_SUPPLY_LOG.setColumnValue("SUPPLY_PRICE", "string", this.txtSUPPLY_PRICE.Text.Trim());
                    ddscDt_SUPPLY_LOG.setColumnValue("ADVISED_PRICE", "string", this.txtADVISED_PRICE.Text.Trim());
                    ddscDt_SUPPLY_LOG.setColumnValue("AVERAGE_PRICE", "string", this.txtAVERAGE_PRICE.Text.Trim());
                    ddscDt_SUPPLY_LOG.setColumnValue("DUTY_FREE_PRICE", "string", this.txtDUTY_FREE_PRICE.Text.Trim());
                    ddscDt_SUPPLY_LOG.setColumnValue("PACKAGE_UNIT", "string", drpPACKAGE_UNIT.SelectedValue);
                    ddscDt_SUPPLY_LOG.setColumnValue("STORE_UNIT", "string", this.drpPACKAGE_UNIT.SelectedValue.Trim());
                    ddscDt_SUPPLY_LOG.setColumnValue("COEFFICIENT", "string", this.txtCOEFFICIENT.Text.Trim());
                    ddscDt_SUPPLY_LOG.setColumnValue("QUOTATION_VALID_DATE", "string", this.txtQUOTATION_VALID_DATE.Text.Trim());
                    ddscDt_SUPPLY_LOG.setColumnValue("PRICE_CHANGE_DATE", "string", SystemDate);
                    ddscDt_SUPPLY_LOG.setColumnValue("CLERK", "string", this.txtCLERK.Text.Trim());
                    ddscDt_SUPPLY_LOG.setColumnValue("CLERK_TEL", "string", this.txtCLERK_TEL.Text.Trim());
                    ddscDt_SUPPLY_LOG.setColumnValue("ORIGINAL_CODE", "string", txtCODE_SEQ.Text.Trim());

                    ddscDt_SUPPLY_LOG.setColumnValue("status", "string", "1");
                    ddscDt_SUPPLY_LOG.setColumnValue("upd_id", "string", VENDOR_NO);
                    ddscDt_SUPPLY_LOG.setColumnValue("upd_date", "string", SystemDate);
                    ddscDt_SUPPLY_LOG.setColumnValue("upd_time", "string", SystemTime);
                    ddscDt_SUPPLY_LOG.setColumnValue("crt_id", "string", VENDOR_NO);
                    ddscDt_SUPPLY_LOG.setColumnValue("crt_date", "string", SystemDate);
                    ddscDt_SUPPLY_LOG.setColumnValue("crt_time", "string", SystemTime);

                    //'Leo Add 20090729 增加五個欄位
                    //ddscDt_SUPPLY_LOG.setColumnValue("PROD_INFO_CHINESE", "string", Me.txtPROD_INFO_CHINESE.Text.ToString)
                    //ddscDt_SUPPLY_LOG.setColumnValue("PROD_INFO_ENGLISH", "string", Me.txtPROD_INFO_ENGLISH.Text.ToString)
                    //ddscDt_SUPPLY_LOG.setColumnValue("PROD_SPEC_CHINESE", "string", Me.txtPROD_SPEC_CHINESE.Text.ToString)
                    //ddscDt_SUPPLY_LOG.setColumnValue("PROD_SPEC_ENGLISH", "string", Me.txtPROD_SPEC_ENGLISH.Text.ToString)
                    //ddscDt_SUPPLY_LOG.setColumnValue("BRAND_ID", "string", Me.drpBRAND_ID.SelectedValue.Trim())

                    //'Leo add end
                    ddscDs.addDataTable(ddscDt_SUPPLY_LOG);
                }
                ddscDs.addDataTable(ddscDt_SUPPLY);
                ddscDs.addDataTable(ddscDt);
                ddscDs.addDataTable(ddscD);
                // 執行新增method
                DataBase DataBase = new DataBase();

                //dsResult = Update(ddscDs)
                dsResult = DataBase.Addition(ddscDs, "", (System.Array)null, (System.Array)null);
                FunctionHandler.InsertMATERIAL_IMAGE(txtCODE_SEQ.Text, SERIAL_ARRAY, IMAGE_ARRAY);

                // 寫入script至client端
                //regScript_MATERIAL_maintain(dsResult, "upd")
                if (this.Request["action_type"].ToString() == "SMAS")
                {
                    regScript(dsResult, "upd", "", "SMAS");
                }
                else
                {
                    regScript(dsResult, "upd");
                }
                regScript(dsResult, "upd");
            }
            catch (System.Data.OracleClient.OracleException ev)
            {
                showException(ev.Message);

                //If Session("langauage") = "zh-tw" Then
                //    strFail = "存檔失敗!\n"
                //Else
                //    strFail = "SAVE FAIL !\n"
                //End If
                //Me.RegisterStartupScript("Result", "<script language=""javascript""> alert('" & strFail & ex.Message & "');window.returnValue = false; </script>")
            }
            catch (Exception ex)
            {
                //myTrans.Rollback()
                showException(ex.Message);
            }
            finally
            {
                // myConnection.Close()
            }

        }
        //delete sub
        private void delMATERIAL(string type)
        {
            // 設定傳送的 DataSet 物件
            com.ddsc.common.ddscDataSet ddscDs = new com.ddsc.common.ddscDataSet();

            VENDOR LoginUser = GetLoginUser();

            // 宣告回傳DataSet
            DataSet dsResult = new DataSet();
            try
            {
                //基本資料
                com.ddsc.common.ddscDataTable ddscDt = ddscDs.createDataTable("B2B_MATERIAL");
                // 新增Row至ddscDt
                ddscDt.addNewRow();
                // 設定dscDt各欄位Value，參數一：columnName,參數二：columnValue
                ddscDt.setColumnValue("action", "string", "upd");
                ddscDt.setColumnValue("CODE", "string", txtCODE_SEQ.Text.Trim());
                ddscDt.setColumnValue("status", "string", "0");
                ddscDt.setColumnValue("upd_id", "string", LoginUser.VENDOR_NO);
                ddscDt.setColumnValue("upd_date", "string", SystemDate);
                ddscDt.setColumnValue("upd_time", "string", SystemTime);
                ddscDt.setWhereValue("CODE", txtCODE_SEQ.Text.Trim());

                ddscDt.addNewRow();
                ddscDt.setColumnValue("action", "string", "del");
                ddscDt.setColumnValue("CODE", "string", txtCODE_SEQ.Text.Trim());
                ddscDt.setWhereValue("CODE", txtCODE_SEQ.Text.Trim());

                com.ddsc.common.ddscDataTable ddscD = ddscDs.createDataTable("B2B_MATERIAL_IMAGE_SEQUENCE");
                // 新增Row至ddscD
                ddscD.addNewRow();
                // 設定dscDt各欄位Value，參數一：columnName,參數二：columnValue
                ddscD.setColumnValue("action", "string", "del");
                ddscD.setColumnValue("CODE", "string", this.txtCODE_SEQ.Text);
                ddscD.setColumnValue("status", "string", "0");
                ddscD.setColumnValue("upd_id", "string", LoginUser.VENDOR_NO);
                ddscD.setColumnValue("upd_date", "string", SystemDate);
                ddscD.setColumnValue("upd_time", "string", SystemTime);
                ddscD.setWhereValue("CODE", this.txtCODE_SEQ.Text);

                ddscD.addNewRow();
                ddscD.setColumnValue("action", "string", "del");
                ddscD.setColumnValue("CODE", "string", this.txtCODE_SEQ.Text);
                ddscD.setWhereValue("CODE", this.txtCODE_SEQ.Text);
                ddscDs.addDataTable(ddscDt);
                ddscDs.addDataTable(ddscD);

                // 執行新增method
                DataBase DataBase = new DataBase();

                //dsResult = Update(ddscDs)
                dsResult = DataBase.Addition(ddscDs, "", (System.Array)null, (System.Array)null);

                // 寫入script至client端
                //regScript_MATERIAL_maintain(dsResult, "del")
                regScript(dsResult, "del");
            }
            catch (Exception ex)
            {
                showException(ex.Message);
            }
            finally
            {
            }
        }

        public void regScript_MATERIAL_maintain(DataSet ds, string action, string msg = "")
        {
            string strResult = System.Convert.ToString(ds.Tables[0].Rows[0]["TransResult"].ToString());
            string strMessage = System.Convert.ToString(ds.Tables[0].Rows[0]["Message"].ToString());
            string strSuccess = "";
            string strFail = "";
            string strClose = "";
            if (Page.Request["action_type"].ToUpper() != "ADD")
            {
                strClose = "window.dialogArguments.location.reload();this.close();";
            }
            try
            {

                if (Session["langauage"] == "zh-tw")
                {
                    if (action == "del")
                    {
                        strSuccess = "刪除成功!";
                        strFail = "刪除失敗!\\n";
                    }
                    else
                    {
                        strSuccess = "存檔成功!";
                        strFail = "存檔失敗!\\n";
                    }

                }
                else
                {
                    if (action == "del")
                    {
                        strSuccess = "DELETE SUCCESS !";
                        strFail = "DELETE FAIL !\\n";
                    }
                    else
                    {
                        strSuccess = "SAVE SUCCESS !";
                        strFail = "SAVE FAIL !\\n";
                    }

                }

                if (strResult == "T")
                {
                    if (!this.IsStartupScriptRegistered("Result"))
                    {
                        this.RegisterStartupScript("Result", "<script language=\"javascript\"> alert(\'" + msg + strSuccess + "\');" + strClose + " </script>");
                    }
                }
                else if (strResult == "")
                {
                    if (!this.IsStartupScriptRegistered("Result"))
                    {
                        this.RegisterStartupScript("Result", "<script language=\"javascript\">window.returnValue = false;</script>");
                    }
                }
                else if (strResult == "F")
                {
                    if (!this.IsStartupScriptRegistered("Result"))
                    {
                        this.RegisterStartupScript("Result", "<script language=\"javascript\"> alert(\'" + msg + strFail + strMessage + "\');window.returnValue = false; </script>");
                    }
                }
            }
            catch (Exception ex)
            {
                showException(ex.Message);
            }
            finally
            {
            }
        }

        private string StringFormat(string sz)
        {
            if (sz.IndexOf(".") == -1)
            {
                return sz;
            }
            else
            {
                return Convert.ToDouble(sz).ToString();
            }

        }

        private void drpADVISED_CURRENCY_TYPE_SelectedIndexChanged(System.Object sender, System.EventArgs e)
        {
            drpADVISED_T_CURRENCY_TYPE.SelectedValue = drpADVISED_CURRENCY_TYPE.SelectedValue;
        }

        private void getBRAND(string strCondition)
        {
            //Dim i As Integer
            DataBase DataBase = new DataBase();
            try
            {
                // 將資料寫入下拉式選單
                if (strCondition != "")
                {
                    strCondition = " AND BRAND_ID=\'" + strCondition + "\'";
                }
                string SelectCommandText = "";
                SelectCommandText = "SELECT BRAND_ID ,BRAND_NAME FROM PRE_BRAND WHERE STATUS=\'1\'" + strCondition;
                DataSet ds = DataBase.Query_CLASS(SelectCommandText, "PRE_BRAND");
                if (!(ds == null) && ds.Tables.Count > 0)
                {
                    if (!(ds == null) && ds.Tables[0].Rows[0]["ReturnCode"] != "100" && ds.Tables[0].Rows[0]["ReturnCode"] != "999")
                    {
                        this.drpBRAND_ID.DataSource = ds.Tables["PRE_BRAND"];
                        this.drpBRAND_ID.DataTextField = "BRAND_NAME";
                        this.drpBRAND_ID.DataValueField = "BRAND_ID";
                        this.drpBRAND_ID.DataBind();
                        if (strCondition == "")
                        {
                            this.drpBRAND_ID.Items.Insert(0, new ListItem("", ""));
                        }

                    }
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
            finally
            {
            }
        }

    }


}
